Here I am showing you how to get coordinates from address using google api (Thanks to Google). The result will solely depends on how google support it in the future. Because google will set the 1st index result for the most relevant, thus this works quite well in general.
Function in php:
function getCoordinates($address){
$address = str_replace(
" "
,
"+"
, $address); // replace
all
the
white
space with
"+"
sign to match with google search pattern
$response = file_get_contents($
url
);
$json = json_decode($response,TRUE); //generate array object from the response from the web
return ($json[
'results'
][
0
][
'geometry'
][
'location'
][
'lat'
].
","
.$json[
'results'
][
0
][
'geometry'
][
'location'
][
'lng'
]);
}
echo getCoordinates('740 Story Rd San Jose CA 95122');
Note*: This article is taken from https://colinyeoh.wordpress.com/2013/02/12/simple-php-function-to-get-coordinates-from-address-through-google-services/
No comments:
Post a Comment
Please Comment Here!