Javascript returns MissingKeyMap 错误中的反向地理编码

Reverse Geocoding in Javascript returns MissingKeyMap error

我正在尝试获取访问我网页的客户的格式化地址。

为此,我编写了函数来获取经纬度,然后将其反向地理编码为格式化地址。

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
 function coordinates_to_address(lat, lng) {
    var latlng = new google.maps.LatLng(lat, lng);
    var geocoder= new google.maps.Geocoder();
    geocoder.geocode({'latLng': latlng}, function(results, status) {
        if(status == google.maps.GeocoderStatus.OK) {
            if(results[0]) {
                $('#address_current').text(results[0].formatted_address);
            } else {
                alert('No results found');
            }
        } else {
            var error = {
                'ZERO_RESULTS': 'No address'
            }

            // alert('Geocoder failed due to: ' + status);
            $('#address_new').html('<span class="color-red">' + error[status] + '</span>');
        }
    });
}

navigator.geolocation.getCurrentPosition(function(location) {
  console.log(location.coords.latitude);
  console.log(location.coords.longitude);
  console.log(location.coords.accuracy);
  var lat= location.coords.latitude;
  var long= location.coords.longitude
  coordinates_to_address(lat, long);
});

</script>

日志显示输出经纬度

    10.8888888888888888
    76.43923530000001
    40

但是这个函数返回了一个错误:

  Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error
  http://maps.google.com/maps/api/js?sensor=false
  Line 34

有没有更简单的方法来获取lat long的格式化地址?

Keys are now required with the Google Maps Javascript API v3(但传感器参数不是)。