Posted By

uberdragon on 08/03/11


Tagged

geocode


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

guillermoj88gmailcom


get Latitude/Longitude from an address


 / Published in: PHP
 

URL: http://amiworks.co.in/talk/how-to-get-latitudelongitude-from-an-address-or-geocoding-using-php/

Convert an address to geocode Latitude/Longitude positioning with PHP and Google Maps

  1. <?php
  2. $address = '201 S. Division St., Ann Arbor, MI 48104'; // Google HQ
  3. $prepAddr = str_replace(' ','+',$address);
  4.  
  5. $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
  6.  
  7. $output= json_decode($geocode);
  8.  
  9. $lat = $output->results[0]->geometry->location->lat;
  10. $long = $output->results[0]->geometry->location->lng;
  11.  
  12. echo $address.'<br>Lat: '.$lat.'<br>Long: '.$long;
  13.  
  14. ?>

Report this snippet  

You need to login to post a comment.