基于谷歌地理编码器中未知地址的建议
当使用谷歌的地理编码器服务在地图上显示城市时;填写不存在的城市会导致错误。
有没有办法根据填写的城市显示一些建议?
var geocoder = new GClientGeocoder();
function showAddress(address, zoom) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
//no point found....
//Suggest some points :)
} else {
map.setCenter(point, zoom);
}
}
);
}
showAddress('Someplace, Nederland', 14);
When using Googles geocoder service to display a city on a map; filling out a non-existing city results in an error.
Is there a way to display some suggestions based on the filled out city?
var geocoder = new GClientGeocoder();
function showAddress(address, zoom) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
//no point found....
//Suggest some points :)
} else {
map.setCenter(point, zoom);
}
}
);
}
showAddress('Someplace, Nederland', 14);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
建议在结果的 Placemarks 属性中返回。我正在使用 v3 并且这有效,请尝试使用 address="Washington Blvd" 来调用它
Suggestions are returned in the Placemarks attribute of the results. I'm using v3 and this works, try calling this with address="Washington Blvd"
如果您只是对城市进行地理编码,您可能需要考虑开始构建自己的城市到坐标缓存。
这是您可能需要考虑的一种方法:
通过这种方法,您还可以播种缓存,以这种方式解析您已经知道 Google 无法进行地理编码的城市名称。
If you are simply geocoding cities, you may want to consider starting to build your own cities-to-coordinates cache.
This is one approach that you may want to consider:
With this approach you can also seed your cache, in such a way to resolve city names which you are already aware that Google is not able to geocode.
如果找到匹配项,它将返回匹配项作为地址,这些就是建议。它不应该返回错误,如果找不到匹配项,它应该只返回一个空列表。你能发布代码吗?
If it finds a match it will return the matches as Addresses and those are the suggestions. It shouldn't return an error, it should just return an empty list if it finds no matches. Can you post the code?