问题
I need a reliable method to get the city, state and country place_id from latitude and longitude.
I'm trying by using Google Maps geocode, but the problem is that some coordinates don't return the administrative_level_1 (state) or the country.
Take this GET request for instance:
https://maps.googleapis.com/maps/api/geocode/json?latlng=-25.4364413,-49.2839333&result_type=country&key=YOUR_API_KEY
It returns:
{
"results": [],
"status": "ZERO_RESULTS"
}
Did you know a way to get this results?
回答1:
This is a bug and it was reported in Google issue tracker in November 2016. Please have a look at bug report and feel free to star it to add your vote.
https://issuetracker.google.com/issues/35829979
I've already added a link to this question in the bug. You can also check workarounds suggested by users in bug comments.
For example, there is following suggestion
I found a workaround: if I do not get a country back, I will do a second reverse geocoding with the coordinates of the highest result I got. Most of the times these coordinates will be in an area, where I can get the country.
This is not ideal, but it works for the cases I found.
I believe you might also be interested in the feature request 'Add place_id in each address_components':
https://issuetracker.google.com/issues/35827596
Feel free to star it as well.
来源:https://stackoverflow.com/questions/46040994/google-maps-geocode-doesnt-return-country