InfoWindow没有在Marker Google Maps JavaScript API v3上面显示

时间:2014-06-27 04:59:29

标签: javascript jquery google-maps google-maps-api-3

所以我创建了一个jsFiddle来演示我的问题:http://jsfiddle.net/6vpc2/1/ 将鼠标悬停在我的jsFiddle中的标记上可以看到InfoWindow的位置。

我有一个GoogleMap"对象"创建谷歌地图。创建Google Map之后:

  var mapOptions = {
    zoom: 8, // The initial zoom level when your map loads (0-20)
    minZoom: 6, // Minimum zoom level allowed (0-20)
    maxZoom: 17, // Maximum soom level allowed (0-20)
    zoomControl: true, // Set to true if using zoomControlOptions below, or false to remove all zoom controls.
    zoomControlOptions: {
        style: google.maps.ZoomControlStyle.DEFAULT // Change to SMALL to force just the + and - buttons.
    },
    //center: location, // Centre the Map to our coordinates variable
    mapTypeId: google.maps.MapTypeId.ROADMAP, // Set the type of Map
    scrollwheel: false, // Disable Mouse Scroll zooming (Essential for responsive sites!)
    // All of the below are set to true by default, so simply remove if set to true:
    panControl: false, // Set to false to disable
    mapTypeControl: false, // Disable Map/Satellite switch
    scaleControl: false, // Set to false to hide scale
    streetViewControl: false, // Set to disable to hide street view
    overviewMapControl: false, // Set to false to remove overview control
    rotateControl: false // Set to false to disable rotate control
}

if (this.instances.length > 0) {
    return this.instances.pop();
}

var googleMap = new GoogleMap();
googleMap.map = new google.maps.Map(googleMap.mapCanvas, mapOptions);
return googleMap;

然后我在JS"对象"中设置var。到返回的googleMap值。

然后我使用this.map,即上面代码中返回的googleMap,在地图上设置标记:

 this.latitude = latitude;
this.longitude = longitude;

var location = new google.maps.LatLng(latitude, longitude);

var infowindow = new google.maps.InfoWindow({
    content: placeMarkerContent
});

this.marker = new google.maps.Marker({
    position: location,
    map: this.map,
});

this.map.setCenter(location);

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

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

问题是InfoWindow没有显示在Marker上方,请参阅我的jsFiddle:http://jsfiddle.net/6vpc2/1/ 将鼠标悬停在我的jsFiddle中的标记上可以看到InfoWindow的位置。

1 个答案:

答案 0 :(得分:1)

在鼠标悬停监听器中使用它时,

this.marker未定义。在单击侦听器函数内部,“this”是标记。

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

fiddle