PHP – Get Latitude/Longitude From an Address with Google Map
The following PHP code convert an address to geocode Latitude/Longitude positioning with Google Maps.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$address = '5001 Teal Plaza,Secaucus,NJ 07094,USA'; // Google HQ //$address = 'NJ 07094,USA'; // Google HQ $prepAddr = str_replace(' ','+',$address); $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false'); $output= json_decode($geocode); $lat = $output->results[0]->geometry->location->lat; $long = $output->results[0]->geometry->location->lng; echo $address.' Lat: '.$lat.' Long: '.$long; |