【问题标题】:Forcing google to give "did you mean" options when using maps/localsearch API使用地图/本地搜索 API 时,强制谷歌提供“你的意思是”选项
【发布时间】:2010-04-26 19:43:41
【问题描述】:
我希望我的应用程序使用谷歌本地搜索和谷歌地图,让我的用户能够在他们的查询有多个可能的答案时从多个位置中进行选择。一个很好的例子是“英国奥弗顿”——这个国家有很多地方都有这个名字,谷歌地图网站给出了几个可能的“你的意思是结果吗”。
但是,API 不会为您提供这些信息。 localsearch 和 GClientGeocoder 都返回一个结果。
有没有办法让 API 返回可能的结果列表?
【问题讨论】:
标签:
google-maps
geocoding
google-local-search
【解决方案1】:
您是否尝试过使用 google.maps.Geocoder()(地图 API 的第 3 版)中的 geocode?我很确定它会返回一个结果数组:
var geocoder = new google.maps.Geocoder();
if(geocoder) {
geocoder.geocode({address: address}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
//do stuff with results, which is an array of address results
}
else {
//error handling
}
});
}
else {
//error handling
}
更多信息请访问Maps API V3 Services。该页面详细介绍了地址结果对象的结构。