I am trying to get latitude and longitude of a place, however, its returning different value than the value provided by google search.
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($request->address).",US&key=API_KEY";
try {
$client = new \GuzzleHttp\Client();
$apiRequest = $client->request('GET', $url);
$resp = json_decode($apiRequest->getBody());
} catch (\Exception $re) {
return response()->json([
'sts' => -1,
'message' => $re->getMessage()],
500);
}
$latitude = $resp->results[0]->geometry->location->lat;
$longitude = $resp->results[0]->geometry->location->lng;
So for testing purpose, I have passed New York
as the address. It returns
[location] => stdClass Object
(
[lat] => 43.2994285
[lng] => -74.2179326
)
However, when I google with keyword lat long of New York
it returns value
40.7128° N, 74.0060° W
I don't get why it is returning the difference of 3 degree
, I understand there could be some minor difference like in this page, however, difference of 3 degree, is quite inconvenient.
Is there something, I might be missing?