2

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?

4

2 回答 2

3

Tarun,我不确定您使用的是哪个 google api。但谷歌地理编码 api 确实允许部分地址搜索并返回按最佳匹配排序的匹配项。所以显示最佳位置应该非常简单。看看下面的这个链接。它返回 xml,但您可以通过将 url 中的 xml 替换为 json 来请求 json。您所要做的就是在此 url 中插入您的部分地址。

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

因此,如果此 url 没有给您任何结果,那么假设该地址不存在可能是安全的。希望帮助

于 2011-05-18T19:09:33.163 回答
0

我绝不是谷歌地图的专家,但我会尝试这样的事情:

1)。获取邮政编码 2)。尝试在此邮政编码内查找街道

如果找到,请标记街道本身并对此感到满意。

于 2011-05-18T19:11:43.067 回答