我在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