views:

29

answers:

2

My users, who may be located anywhere in the world, will be presented with a text box wherein they can enter their address. In most cases, I assume they will physically be in the same country as whatever address they are typing.

I'd like to help Google Map API make better guesses by doing region biasing (http://code.google.com/apis/maps/documentation/geocoding/#RegionCodes). Is there a way to tell Google to region bias from where the request is being made? Or how can I give that information to Google when I make the web service call (e.g. convert IP address to country information)?

Thanks.

A: 

In modern browsers you can use the HTML5 Geolocation API as described in Dive Into HTML5. This assumes client-side support and that you're making the requests client-side. For a server-side (or fallback) solution, you could try something like the PHP Geo IP functions.

You
+1  A: 

The last time I checked, the "region bias" for both the client-side and the server-side Google Geocoder was not reliable. Check out this post from last April (tested again right now, and the issue persists):

The most reliable way that I found is to append the country at the end of the address. Therefore if the user is located in the UK, and types "Oxford Street London", you'd attach ", UK" to the address for geocoding.

To get the country of the user, there are quite a few solutions. You could use the Geolocation API as @You suggested in the other answer, or you may want to use a third party IP-to-location service. You may want to check out MaxMind GeoLite City service, which is free, and is reportedly 99.5% accurate on a country level.

Daniel Vassallo
@Daniel, I have a concern with appending the country at the end of the address. What if the user already provides the country?
StackOverflowNewbie
@StackOverflowNewbie: Yes, that could be tricky to handle unless you will have different text boxes for street, city and country.
Daniel Vassallo
@Daniel, I'm trying to keep it simple and keep it as just 1 text box. I'll look into your suggestions and see what I can come up with. Thanks.
StackOverflowNewbie