使用Google Maps API,如何在反向地理编码时限制准确性?

时间:2010-05-21 12:58:59

标签: google-maps geolocation

我想限制对GClientGeocoder.getLocations的调用的准确性,以便它只返回精确度为0到3的结果,即从未知到子区域。

想法是找到用户点击的粗略区域。

1 个答案:

答案 0 :(得分:1)

getLocations()返回包含数组的响应。走完阵列,直到找到具有所需细节水平的地标。例如,假设getLocations()的回调具有响应参数,请使用以下代码:

for (var i=0; i<response.Placemark.length; i++) {
  if (response.Placemark[i].AddressDetails.Accuracy < 4) {
    alert(response.Placemark[i].address);
    break;
  }
}