我可以在地图上设置图钉,但我无法检索该点的纬度和经度。这是我的代码。任何人都可以帮忙吗?
由于
function codeaddress() {
var geocoder;
//map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
animation: google.maps.Animation.BOUNCE,
flat: false,
map: map,
position: results[0].geometry.location
});
var latt = document.getElementById("latitude");
latt.value = results[0].geometry.location.getlatitude();
alert(latt.value);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
答案 0 :(得分:1)
尝试使用.lat()
代替.getLatitude()
。
请参阅有关LatLng类的API:https://developers.google.com/maps/documentation/javascript/reference#LatLng