I am trying to widen the search results returned by geocoding. I'm essentially createing a jquery ui autocomplete input like this http://tech.cibul.org/wp-content/uploads/2010/05/geocode/index.html (tutorial here http://tech.cibul.org/geocode-with-google-maps-api-v3/).
For example if I enter 'waterloo' in the location bar I get 1 option: Waterloo, ON, Canada.
What about all of the other Waterloos? http://en.wikipedia.org/wiki/Waterloo
This is the crux of the code:
$('input[name="location"]').autocomplete({
source: function(request, response) {
geocoder.geocode( {'address': request.term }, function(results, status) {
r开发者_开发问答esponse($.map(results, function(item) {
return {
label: item.formatted_address,
value: item.formatted_address,
latitude: item.geometry.location.lat(),
longitude: item.geometry.location.lng()
}
}));
})
}
});
In my experience, it is impossible to get the Geocoding API to make a sane list of location suggestions even with V3 and region biasing (related question here).
What you get through the API varies greatly from what you get when entering an ambiguous name in the Maps application. I am not aware of any workaround.
I've reached the conclusion that if you want to offer a list of place names, you need some other data source, for example Wikipedia's list of cities.
精彩评论