Geocode from Google API V3

If you want to get the latitude and longitude from an address using PHP then try the following code snippet:

$geoResult = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($addressString) . '&sensor=false&key=API');
if ($geoResult !== FALSE) {
$output= json_decode($geoResult);
@$lat = $output->results[0]->geometry->location->lat;
@$long = $output->results[0]->geometry->location->lng;
if ($output->status == 'OK') {
if ($lat > NULL) {
//do something
}
}
}

Leave a Reply