-2
我試圖獲取訪問我的網頁的客戶的格式化地址。Javascript中的反向地理編碼返回MissingKeyMap錯誤
爲此,我寫了函數獲取經緯度,然後將其地址解析爲格式化地址。
<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>
日誌顯示輸出Lat Long網
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
有沒有更簡單的方法來獲取經緯度長的格式的地址?