geocode.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  5. if(isset($_GET['text'])) {
  6. $url = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest';
  7. $data = array('f' => 'pjson',
  8. 'searchExtent' => '{"xmin":-0.5,"ymin":49.732307856286,"xmax":-1.97117692088061,"ymax":48.4,"spatialReference":{"wkid":84}}',
  9. 'text' => $_GET['text']
  10. );
  11. //url-ify the data for the POST
  12. $url_data = http_build_query($data);
  13. $ch = curl_init();
  14. //set the url, number of POST vars, POST data
  15. curl_setopt($ch,CURLOPT_URL, $url);
  16. curl_setopt($ch,CURLOPT_POST, true);
  17. curl_setopt($ch,CURLOPT_POSTFIELDS, $url_data);
  18. //So that curl_exec returns the contents of the cURL; rather than echoing it
  19. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  20. //execute post
  21. $result = curl_exec($ch);
  22. echo $result;
  23. }
  24. if(isset($_GET['address'])|isset($_GET['magicKey'])) {
  25. $url = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find';
  26. $data = array('f' => 'pjson',
  27. 'searchExtent' => '{"xmin":-0.5,"ymin":49.732307856286,"xmax":-1.97117692088061,"ymax":48.4,"spatialReference":{"wkid":84}}',
  28. 'magicKey' => $_GET['magicKey'],
  29. 'text' => $_GET['address']
  30. );
  31. //url-ify the data for the POST
  32. $url_data = http_build_query($data);
  33. // var_dump($url_data);
  34. $ch = curl_init();
  35. //set the url, number of POST vars, POST data
  36. curl_setopt($ch,CURLOPT_URL, $url);
  37. curl_setopt($ch,CURLOPT_POST, true);
  38. curl_setopt($ch,CURLOPT_POSTFIELDS, $url_data);
  39. //So that curl_exec returns the contents of the cURL; rather than echoing it
  40. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  41. //execute post
  42. $result = curl_exec($ch);
  43. echo $result;
  44. }
  45. ?>