get Latitude/Longitude from an address


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.