Javascript Google将API2映射到API3-未捕获类型错误:无法读取属性';地图';未定义的
我正忙着将地图从api2移动到API3,并在途中遇到一些颠簸。当使用下面的代码时,我会得到一个灰色块,并且贴图不会渲染。控制台显示“未捕获的TypeError:无法读取未定义的属性“Map”。我正在编辑别人的作品,所以我对这件事还不是很了解,请告诉我你是否能发现一些东西或者是否需要更多的细节Javascript Google将API2映射到API3-未捕获类型错误:无法读取属性';地图';未定义的,javascript,google-maps,google-maps-api-3,google-maps-api-2,Javascript,Google Maps,Google Maps Api 3,Google Maps Api 2,我正忙着将地图从api2移动到API3,并在途中遇到一些颠簸。当使用下面的代码时,我会得到一个灰色块,并且贴图不会渲染。控制台显示“未捕获的TypeError:无法读取未定义的属性“Map”。我正在编辑别人的作品,所以我对这件事还不是很了解,请告诉我你是否能发现一些东西或者是否需要更多的细节 // Initialise the required maps Tour_Map = new Object(); Tour_Map.maps = new Array(); if (typeof (Tou
// Initialise the required maps
Tour_Map = new Object();
Tour_Map.maps = new Array();
if (typeof (Tour_Map.GoogleMap) == 'undefined' || (!Tour_Map.GoogleMap instanceof Object)) {
Tour_Map.GoogleMap = function() {
function Map (init, options) {
// Check that we have the required information.
if (init == null
|| typeof (init) != 'object'
|| typeof (init.map_container) == 'undefined') {
alert('init failed');
return false;
}
// Only proceed if the map container is visible
if ($('#' + init.map_container).is(":visible")) {
// Set the default map options.
var map_options = {
'url': null,
'zoom': 4,
'lat': -3.5777508205127946,
'lng': 28.1195068359375,
'enableGoogleBar': 0,
'googleBarOptions': {style: "new"},
'directions': null,
'markers': null,
'route': null,
'map': null
}
//Create map
var __map = new google.maps.Map(
document.getElementById(init.map_container), {
center: new google.maps.LatLng(map_options.lat, map_options.lng),
zoom: map_options.zoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Return the Google Map
this.__map = __map;
return this;
} // if map container is visible
else {
return null;
}
} // Map constructor end
// Return our publically-accessible object.
return ({Map: Map});
}();
}
$(window).load(function() {
// Create the Google Maps by looping through the maps array created earlier
if (typeof (Tour_Map.maps) !== 'undefined') {
for (var i in Tour_Map.maps) {
Tour_Map.maps[i].map = new Tour_Map.GoogleMap.Map(Tour_Map.maps[i].init, Tour_Map.maps[i].options);
}
}
});
循环通过允许创建多个地图,在具有地图特色的页面上,有以下代码:
DSA_Map.maps.push({
init : {
map_container: 'map_branches'
},
options: {
zoom : 5,
lat : -23.92175976307374,
lng : 24.120724868774414,
directions: 1,
markers : [{exp:channel:entries orderby="title" sort="asc" channel="locations" dynamic="off" category="12|13|14" limit="5000" disable="{lv_disable_all}" {lv_tag_caching}}{exp:tied_entries this_entry_id="{entry_id}" tie="<branches" allow_php="yes" orderby="title" sort="asc"}<?php $locations[] = '<dd class="location">{title} <a class="expander">+</a></dd>'."\n";$locations[] = '<dd class="branch"><a href="#map_branches" id="marker_index'.$i++.'">{tied:title}</a></dd>'."\n"; ?>{embed="branch-finder/.js" entry_id="{tied:entry_id}" count="<?php echo $i;$i++; ?>"},{/exp:tied_entries}{/exp:channel:entries}]
}
});
DSA_Map.maps.push({
初始化:{
映射容器:“映射分支”
},
选项:{
缩放:5,
纬度:-23.92175976307374,
液化天然气:24.120724868774414,
方向:1,,
标记:[{exp:channel:entries orderby=“title”sort=“asc”channel=“locations”dynamic=“off”category=“12 | 13 | 14”limit=“5000”disable=“{lv_disable_all}{lv u tag u caching}}{exp:tied_entries this_entry_id=“{entry_id}”tie=“您可以添加plnkr或JSFIDLE吗?您是否在代码之前包含Google Maps Javascript API v3?这似乎是一种稍微复杂的处理方式。您在什么时候填充Tour\u Map.Maps
以使此循环有一些内容可以迭代?用于(Tour\u Map.Maps中的变量i){
评论说,
//通过在前面创建的Maps数组中循环创建Google地图,实际上是:Tour_Map.Maps=new array();
…从我在代码中看到的内容来看,该数组中没有插入任何内容