views:

34

answers:

1

For the site I am building I want the user to be able to search for a location, however because I don't have a list of locations for the UK, I have developed a script in PHP which calls: http://ajax.googleapis.com/ajax/services/search/local in order to get the lat and lon coordinates of this location to store in the database for future use.

This works well apart from if I search for a town, for example Heaton, it brings back the one in Staffordshire rather than the one in Newcastle for example.

The whole reason I'm using the google ajax api is to cut down the google requests per day because I don't want to exceed the daily request limit.

As you can see though, I've hit a brick wall because the search isn't refined enough to bring back the correct location.

Can anyone suggest another way around this? I'm quite stuck. Thanks

+1  A: 

I don't know if you have seen this already, but there is a parameter in the Google Search API that allows you to specify a boundary for the search:

GeocoderRequest object specification

The specification for a geocoding request to be sent to the Geocoder.

Properties  Type         Description
address     string       Address. Optional.
bounds      LatLngBounds LatLngBounds within which to search. Optional.
language    string       Preferred language for results. Optional.
location    LatLng       LatLng about which to search. Optional.
region      string       Country code top-level domain within which to search.

In your case I would specify a bounds around northumberland, so something like:

http://ajax.googleapis.com/ajax/services/search/local?q=heaton&v=3.1&region=GB&sensor=false&bounds=(55.395,%20-2.510%20,2054.342,%20-0.417)

might work...? I don't know if this would be relevant to your app though. Good luck!

Kevin Sedgley