【发布时间】:2013-02-23 22:02:08
【问题描述】:
我可以在地图上设置图钉,但我无法检索该点的纬度和经度。这是我的代码。有人可以帮忙吗?
谢谢
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);
}
});
}
【问题讨论】:
-
这需要先进行基本调试。到底哪里出了问题?
-
你试过 results[0].geometry.location.lat()
-
Rafe,尝试了结果[0].geometry.location.lat()。没有得到纬度。
-
Chrome 未显示更新的页面。当我运行应用程序时,我在 javascript 中所做的任何代码更改都没有反映出来。稍后添加了我试图检索纬度和经度的代码部分。这些变化没有反映出来。当我在 chrome 上删除浏览历史记录时,我能够看到更改。
标签: javascript asp.net google-maps