1

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) {
            response($.map(results, function(item) {
                return {
                    label: item.formatted_address,
                    value: item.formatted_address,
                    latitude: item.geometry.location.lat(),
                    longitude: item.geometry.location.lng()
                }
            }));
        })
    }
});

1 Answers1

0

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.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Yes I guess I'll have to look at another route. The wikipedia idea is good except I don't want to narrow the list down, on bias the returned order to show UK, US results first. For example I'd still like a user to be able to choose a town in whether it be in Congo, China, US, Venezuela, UK or Germany. Damn, I wouldn't have imagined this would have been so hard. –  Apr 06 '11 at 14:55
  • @Colin I know, it stinks. Google have all the data, they should be able to provide a list of cities no problem... But for some reason, they won't. If you find a solution for this within the Maps API, I'd appreciate a ping, I've settled for a compromise at the moment. But as far as I can see, there is no way. – Pekka Apr 06 '11 at 14:59
  • check out my update on this question: http://stackoverflow.com/questions/5555307/smart-location-form-field - I've worked something up here http://jsfiddle.net/ekzMN/95/ and combine this with Google Geocoder as a secondary source to provide samrter results. It needs a bit of work though. Let me know if you come up with any improvements. I've marked this as correct as it's impossible using Google Geocoder alone. –  Apr 14 '11 at 15:20
  • @Colin very interesting, thanks for the link! I will check it out. – Pekka Apr 14 '11 at 15:22
  • also check out this http://stackoverflow.com/questions/5714477/global-location-input-autocomplete I created a jquery plugin. –  Apr 19 '11 at 14:32