Question

This question is regarding the google Maps API geocoding, I'm able to geocode an address and show the location, but this works when the address is valid.

When it's not valid(there is an error),right now, I'm showing a smart message which says there is an error retrieving the location, but the requirement is to show the nearest possible location to the entered address.

How do I get the marker on next best location?

here's what I've tried:

Split the address, based on commas, and geocode each substring, and get the marker on the 1st match, but this resulted in some huge errors.

What I'm thinking of doing now is:

geocode the zip-code using yahoo maps API, but the only problem is I don't think it will be close to what the user has entered as his address.

Any solutions?

Was it helpful?

Solution

Tarun , i am not sure which google api you are using. But Google geocoding api does allow for partial address searches and returns matches sorted by best fit. So displaying best location should be really simple. Take a look at this link below. It returns xml but you can ask for json by replacing xml in url with json. All you have to do insert your partial address in this url.

http://maps.googleapis.com/maps/api/geocode/xml?address=holly%20hall&sensor=false

So if this url doesnt give you any results, then its probably safe to assume that address doesn't exist. Hope that hepls

OTHER TIPS

I'm by no means an expert of Google Maps, but I would try something like this:

1). Get the zip code 2). Try to find the street within this zip code

If found, mark the street itself and be happy with that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top