我有一个谷歌地图设置,其中数据来自mySql后端,我将以编码字符串形式存储。 我可以正确显示地图中的数据,但无法提供外部链接。
for (x = 0; x < stringArray.length; x = x + 1)
{
var addressDetails = [];
var marker;
//Separate each field
addressDetails = stringArray[x].split("&&&");
//Load the lat, long data
var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]);
//Create a new marker and info window
var y = x+1;
marker = new google.maps.Marker({
map: map,
position: lat,
content: addressDetails[0],
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='+y+'|FF0000|000000'
});
//Pushing the markers into an array so that it's easier to manage them
markersArray.push(marker);
google.maps.event.addListener( marker, 'click', function () {
closeInfos();
var info = new google.maps.InfoWindow({content: this.content});
//On click the map will load the info window
info.open(map,this);
infos[0]=info;
});
//Extends the boundaries of the map to include this new location
bounds.extend(lat);
}
//Takes all the lat, longs in the bounds variable and autosizes the map
map.fitBounds(bounds);
此代码用于外部点击。
function myclick(i) {
google.maps.event.trigger(markersArray[i], "click");
}
我得到的错误是: “未捕获的ReferenceError:myclick未定义”
请指导我出错的地方?
谢谢,
答案 0 :(得分:1)
根据您尝试拨打myclick
的方式,您需要将其附加到window
对象:
window.myclick = function(i) {
console.log('I am defined and available in the global scope via window!');
}