我在这里阅读了一些主题,并且我知道我的属性在函数globalSettings
中不可用存在范围问题。google.maps.event.addDomListener
该console.log
语句返回undefined
,但如果我这样做console.log(globalSettings)
,它会显示对象及其属性。
如何使属性可用,以便我可以使用它们来初始化地图中心和缩放?
var globalSettings = jQuery.parseJSON(wpmm_settings);
var ICON = new google.maps.MarkerImage('medicare.png', null, null,
new google.maps.Point(14, 13));
var SHADOW = new google.maps.MarkerImage('medicare-shadow.png', null, null,
new google.maps.Point(14, 13));
google.maps.event.addDomListener(window, 'load', function(globalSettings) {
console.log(globalSettings.map_center_lat);
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(globalSettings.map_center_lat, 135),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
});...