How to get a latitude and longitude using google map api, create account to console and enable google map api and geocode api, and get api and put in this url
https://maps.googleapis.com/maps/api/geocode/json?address=$address&key=Your API key
Here is php function to pass address and get lat long in a return value
// function to get the address
public function GetLatLong($address){
$address = str_replace(" ", "+", $address);
$json = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=$address&key=Your API key");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
return $lat.','.$long;
}
No comments:
Post a Comment