问题
The problem is simple, in the documentation for the Geocoding API they say component filtering exists. (Source: https://developers.google.com/maps/documentation/geocoding/)
However, if I look at the JS documentation (https://developers.google.com/maps/documentation/javascript/geocoding), it doesn't seem to be implemented. I do however remember that google earlier used to have features implemented but not written about in their API, so I wonder if anyone knows how to achieve component filtering with the Google Maps Geocoding API?
Thanks!
回答1:
The documentation seems to of implemented it now. Either way, here is the code:
geocoder.geocode(
{ 'address': address, 'componentRestrictions':{'country':'GB'}},
function(results, status){
...
});
Used to restrict results to a specific area. A filter consists of one or more of: route, locality, administrativeArea, postalCode or country. Only the results that match all the filters will be returned. Filter values support the same methods of spelling correction and partial matching as other geocoding requests. See Component Filtering in the Geocoding web service for further details.
来源:https://stackoverflow.com/questions/17201535/google-maps-geocoding-api-feature-from-the-api-missing-in-their-js-api