我在JavaScript中有像更新全局變量在JavaScript
var EventLocation = {
'center' : '35.59214,-121.046048',
'zoom' : 10
};
一個全局變量,現在在函數,我們更新這個變量作爲
var geocoder = new google.maps.Geocoder();
var address = $j('#EventLocation').text(); //record.Location;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
EventLocation.center = new google.maps.LatLng(latitude, longitude);
//onSuccessMaps(latitude,longitude);
} else {
alert('Fail to find location');
}
});
但在另一種功能EventLocation.center不更新,它以前值爲('35.59214,-121.046048')
。 我該如何解決這個問題?
凡EventLocation被定義?在函數或頂級腳本文件/標籤內? – Nathan 2012-03-13 06:58:09
您是否嘗試將中心屬性從開始更改爲Google地圖latlng對象? – 2012-03-13 07:00:02
嘗試'window.EventLocation.center = new google.maps.LatLng(latitude,longitude);' – Nemoy 2012-03-13 07:00:04