geocode.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // $fp = fopen(dirname(__FILE__).'/suggest.log', 'w');
  19. // curl_setopt($ch, CURLOPT_VERBOSE, 1);
  20. // curl_setopt($ch, CURLOPT_STDERR, $fp);
  21. //So that curl_exec returns the contents of the cURL; rather than echoing it
  22. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  23. //execute post
  24. $result = curl_exec($ch);
  25. echo $result;
  26. }
  27. if(isset($_GET['address'])|isset($_GET['magicKey'])) {
  28. $url = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find';
  29. $data = array('f' => 'pjson',
  30. 'searchExtent' => '{"xmin":-0.5,"ymin":49.732307856286,"xmax":-1.97117692088061,"ymax":48.4,"spatialReference":{"wkid":84}}',
  31. 'magicKey' => $_GET['magicKey'],
  32. 'text' => $_GET['address']
  33. );
  34. //url-ify the data for the POST
  35. $url_data = http_build_query($data);
  36. // var_dump($url_data);
  37. $ch = curl_init();
  38. //set the url, number of POST vars, POST data
  39. curl_setopt($ch,CURLOPT_URL, $url);
  40. curl_setopt($ch,CURLOPT_POST, true);
  41. curl_setopt($ch,CURLOPT_POSTFIELDS, $url_data);
  42. // $fp = fopen(dirname(__FILE__).'/find.log', 'w');
  43. // curl_setopt($ch, CURLOPT_VERBOSE, 1);
  44. // curl_setopt($ch, CURLOPT_STDERR, $fp);
  45. //So that curl_exec returns the contents of the cURL; rather than echoing it
  46. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  47. //execute post
  48. $result = curl_exec($ch);
  49. echo $result;
  50. }
  51. ?>