2013-07-15 165 views
1

我有一个谷歌地图设置,其中的数据来自mySql后端,我存储在编码字符串中。 我可以正确显示地图中的数据,但无法提供外部链接。谷歌地图infowindow的外部链接

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"); 
    } 

我得到的错误是:“:没有定义了MyClick未捕获的ReferenceError”

请指导,我已经出了错 ?

感谢,

+0

任何帮助将不胜感激。 – ankitjain11

+0

你在哪里绑定'myclick'? –

+0

我没有得到你,对不起。你是说,我在哪里打电话给这个活动? – ankitjain11

回答

1

鉴于你试图调用myclick的方式,你需要将它连接到您的window对象:

window.myclick = function(i) { 
    console.log('I am defined and available in the global scope via window!'); 
} 

Here's a demo

+0

谢谢....无缝工作。 – ankitjain11