0
我正在開發一個MVC asp.net項目。在頁面#1我需要發佈長和緯度座標(用戶的地址),以便服務器可以返回正確的信息以顯示在第2頁的谷歌地圖上。沒有地圖的點擊事件上的Geocache
我在頁面#2上使用Google Map Javascript API V3,並且希望在頁面#1上使用它。
我正在使用此代碼...有時它可以工作,而其他時間則不會。它通常在調試模式下工作。所以我猜想某種時機問題。我想不明白。
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
geocoder = new google.maps.Geocoder();
}
function submitClick() {
var address = "Amsterdam, Netherlands";
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
alert(lat + " and " + lng)
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
我還是新來的谷歌地圖api,所以我假設我只是用它錯誤的方式。謝謝你的幫助。