douxiaochun4964
2014-09-01 07:39
浏览 45
已采纳

谷歌地图Infowindow没有正确显示,但当我打开冷杉时,它运作良好

The infowindow is not showing properly on my map when clicking on a marker. The website is here.

You'll also notice the map control isn't properly displayed either.

var map;
var locations = <?php print json_encode(di_get_locations()); ?> ;
var markers = []
jQuery(function ($) {
    var options = {
        center: new google.maps.LatLng(51.840639771473, 5.8587418730469),
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), options);

    for (var i = 0; i < locations.length; i++) {
        makeMarker(locations[i]);
    }
    centerMap();

});

function makeMarker(location) {
    var markerOptions = {
        map: map,
        position: new google.maps.LatLng(location.lat, location.lng)
    };
    var marker = new google.maps.Marker(markerOptions);
    markers.push(marker);
    var content = '';

    var infowindow = new google.maps.InfoWindow({
        content: "test",
        size: new google.maps.Size(50, 50),
        disableAutoPan: true
    });


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

function centerMap() {
    map.setCenter(markers[markers.length - 1].getPosition());
}

图片转代码服务由CSDN问答提供 功能建议

单击标记时,我的地图上的信息窗口显示不正确。 网站就在这里。

您还会注意到地图控件也没有正确显示。

  var map; 
var  locations =&lt;?php print json_encode(di_get_locations());  ?&GT;  ; 
var markers = [] 
jQuery(function($){
 var options = {
 center:new google.maps.LatLng(51.840639771473,5.8587418730469),
 zoom:8,
 mapTypeId:google.maps  .MapTypeId.ROADMAP 
}; 
 map = new google.maps.Map(document.getElementById(“map_canvas”),options); 
 
 for(var i = 0; i&lt; locations.length; i ++  ){
 \ makeMarker(locations [i]); 
} 
 centerMap(); 
 
}); 
 
function makeMarker(location){
 var markerOptions = {
 map:map,\ 位置:new google.maps.LatLng(location.lat,location.lng)
}; 
 var marker = new google.maps.Marker(markerOptions); 
 markers.push(marker); 
 var content  =''; 
 
 var infowindow = new google.maps.InfoWindow({
 content:“test”,
 size:new google.maps.Size(50,50),
 disableAutoPan:true 
  }); 
 
 
 google.maps.event.addListener(marker,'click',function(e){
 infowindow.open(map,marker); 
}); 
} 
 \  nfunction centerMap(){
m  ap.setCenter(markers [markers.length  -  1] .getPosition()); 
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题