Find nearest known location: Google Reverse Geocoding

余生长醉 提交于 2019-12-08 10:04:30

You need to modify the if condition inside getLocation function. Check for results[0] not result[1].

if (status == google.maps.GeocoderStatus.OK) {
      if (results[0]) {
            document.getElementById('spanId').innerHTML = results[0].formatted_address + ', ' + distance + ' kms away from original point' ;
      } else {
              window.alert('No results found');
      }
} else {
       window.alert('Geocoder failed due to - ' + status)
}

ZERO_RESULTS from Reverse Geocoding in the Google Geocoding API typically mean the latlng is in a body water far off shore (oceans, seas, really big lakes, etc.) or in an area with a territorial dispute. This is a known issue: https://code.google.com/p/gmaps-api-issues/issues/detail?id=8783

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!