I have a code for get lat & long from address and find lat , long successfully.But some address not find lat and long and skip the code.here is my code.Please help me.
$address = 'Street 1, City, Country'; // Your address
$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.'<br>Lat: '.$lat.'<br>Long: '.$long;
That probably means that no address with such name has been found.
To check this you can use status field in response as such:
if (strtolower($output->status) == 'ok') {
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
} else {
// return error ie. throw new Exception('No such address');
}
echo $address.'<br>Lat: '.$lat.'<br>Long: '.$long;