Google maps api 3 谷歌地图api v3:地理编码多个地址和信息窗口

Google maps api 3 谷歌地图api v3:地理编码多个地址和信息窗口,google-maps-api-3,infowindow,Google Maps Api 3,Infowindow,我正在尝试获取多个地址的信息窗口。它正在创建标记,但当我点击标记时,信息窗口并没有弹出。请帮助并查看此代码中可能存在的错误。Rest所有信息都很好,唯一的问题是信息窗口没有打开 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Google Maps Multi

我正在尝试获取多个地址的信息窗口。它正在创建标记,但当我点击标记时,信息窗口并没有弹出。请帮助并查看此代码中可能存在的错误。Rest所有信息都很好,唯一的问题是信息窗口没有打开

<!DOCTYPE html>
<html> 
<head> 
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
  <title>Google Maps Multiple Markers</title> 
  <script src="http://maps.google.com/maps/api/js?sensor=false" 
          type="text/javascript"></script>
</head> 
<body>
  <div id="map" style="height: 800px;"></div>

  <script type="text/javascript">
    var locations = [
      ['Bondi Beach', '850 Bay st 04 Toronto, Ont'],
      ['Coogee Beach', '932 Bay Street, Toronto, ON M5S 1B1'],
      ['Cronulla Beach', '61 Town Centre Court, Toronto, ON M1P'],
      ['Manly Beach', '832 Bay Street, Toronto, ON M5S 1B1'],
      ['Maroubra Beach', '606 New Toronto Street, Toronto, ON M8V 2E8']
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(43.253205,-80.480347),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();
    var geocoder = new google.maps.Geocoder();

    var marker, i;

    for (i = 0; i < locations.length; i++) {

        geocoder.geocode( { 'address': locations[i][1]}, function(results, status) {
            //alert(status);
            if (status == google.maps.GeocoderStatus.OK) {

                //alert(results[0].geometry.location);
                map.setCenter(results[0].geometry.location);
                marker = new google.maps.Marker({
                    position: results[0].geometry.location,
                    map: map
                }); 

                google.maps.event.addListener(marker, 'mouseover', function() { infowindow.open(marker, map);});
                google.maps.event.addListener(marker, 'mouseout', function() { infowindow.close();});

            }
            else
            {
                alert("some problem in geocode" + status);
            }
        }); 
    }

  </script>
</body>
</html>

谷歌地图多个标记
变量位置=[
['Bondi Beach','850 Bay st 04多伦多,安大略省'],
['Coogee Beach','932 Bay Street,多伦多,M5S 1B1'],
['Cronulla Beach','多伦多市中心法院61号,M1P'],
['Manly Beach','832 Bay Street,多伦多,M5S 1B1'],
['Maroubra海滩','606新多伦多街,多伦多,M8V 2E8']
];
var map=new google.maps.map(document.getElementById('map'){
缩放:10,
中心:新google.maps.LatLng(43.253205,-80.480347),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var infowindow=new google.maps.infowindow();
var geocoder=new google.maps.geocoder();
var标记,i;
对于(i=0;i
您有google.maps.InfoWindow.open方法的参数:

打开(地图?:地图|街景全景,锚?:MVCObject)|无|打开给定地图上的此信息窗口。或者,信息窗口可以与锚关联。在核心API中,唯一的锚点是Marker类。但是,定位点可以是任何MVCObject,该MVCObject公开了LatLng position特性和用于计算像素偏移的点定位点特性(可选)(请参见InfoWindowOptions)。锚点是从锚点位置到信息窗口顶端的偏移

应该是:

google.maps.event.addListener(marker, 'mouseover', function() { infowindow.open(map, marker);});

为了避免与
标记的范围有关的问题,您可以执行以下两种操作之一

1. 将
marker
设置为
geocoder.geocode()
回调的本地:

var marker = new google.maps.Marker({...});
并更正传递到
infowindow.open()的参数顺序:

2. 使用
this
,从标记自身的事件处理程序中可靠地引用回标记,如下所示:

google.maps.event.addListener(marker, 'mouseover', function() {
    infowindow.open(map, this);
});
就个人而言,我会使用方法2

google.maps.event.addListener(marker, 'mouseover', function() { infowindow.open(map, marker);});
google.maps.event.addListener(marker, 'mouseover', function() {
    infowindow.open(map, this);
});