I am receiving many times only types plus_code
for my google map requests.
I have a code which fetches the administrative_area_3 2 or locality and am not interested in plus codes.
I do reverse geocode for particular coordinates.
One such example is the point with lat lng '42.6552808', '20.4036742',
for which reverse geocode returns
{
"plus_code" :
{
"global_code" : "8GJ2MC43+4F7"
},
"results" :
[
{
"address_components" :
[
{
"long_name" : "8GJ2MC43+4F",
"short_name" : "8GJ2MC43+4F",
"types" :
[
"plus_code"
]
}
],
"formatted_address" : "8GJ2MC43+4F",
"geometry" :
{
"bounds" :
{
"northeast" :
{
"lat" : 42.655375,
"lng" : 20.40375
},
"southwest" :
{
"lat" : 42.65525,
"lng" : 20.403625
}
},
"location" :
{
"lat" : 42.6552808,
"lng" : 20.4036742
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" :
{
"northeast" :
{
"lat" : 42.6566614802915,
"lng" : 20.4050364802915
},
"southwest" :
{
"lat" : 42.6539635197085,
"lng" : 20.4023385197085
}
}
},
"place_id" : "GhIJLtnCPeBTRUARLD0_MVdnNEA",
"plus_code" :
{
"global_code" : "8GJ2MC43+4F"
},
"types" :
[
"plus_code"
]
}
],
"status" : "OK"
}
My php code for the request is
$this->httpClient->get(
'https://maps.googleapis.com/maps/api/geocode/json,
[
RequestOptions::HTTP_ERRORS => false,
RequestOptions::QUERY => [
'key' => 'mykey',
'latlng' => sprintf('%s,%s', $latitude, $longitude),
'components' => 'country|locality',
'language' => (string)$locale
]
]
);
There is only 1 result of type plus_code, no other results with locality, administrative area or something more "meaningful" like a containing entity.
So the question is:
How can I get the city/village/locality/whateveradmare of some location when I get back only a plus code in the response?
My thoughts atm: Just try reverse geocode with some km distance nearby in a while loop until i get back the next division