谷歌地图中的移动端触发

Moveend triggering in Google Maps

本文关键字:移动 谷歌地图      更新时间:2024-05-01

我正试图在访问者移动地图后通过Json添加标记。由于某些原因,moveend未被捕获和/或函数onClickCallback未被触发。我哪里错了。

 google.maps.event.addListener(map, "moveend", function() {
  var bounds = this.getBounds();
  onClickCallback(map);
 });

function onClickCallback(map) {
var bounds = map.getBounds();

  // clearOverlays();

    $.getJSON( 'http://skiweather.eu/gmap4/markers/index.php', {
        swLat: bounds.getSouthWest().lat(), swLon: bounds.getSouthWest().lng(), 
        neLat: bounds.getNorthEast().lat(), neLon: bounds.getNorthEast().lng()}, function(data) { 
        $.each( data.markers, function(i, marker) {

        // Define Marker properties
        var image = new google.maps.MarkerImage(marker.smallimg,
        // This marker is 129 pixels wide by 42 pixels tall.
            new google.maps.Size(42, 42),
        // The origin for this image is 0,0.
            new google.maps.Point(0,0),
        // The anchor for this image is the base of the flagpole at 18,42.
            new google.maps.Point(18, 42)
        );

            $('#map').gmap('addMarker', { 'id' : marker.id,
                'position': new google.maps.LatLng(marker.latitude, marker.longitude),
                'icon' : image,             
                'bounds': true 
            }).click(function() {
                $('#map').gmap('openInfoWindow', { 'content': '<h2>' + marker.loc + '</h2><img src="' + marker.smallimg + '" class="my-map-marker" />'
                 }, this);
            });
        });
    });


}   

google.maps.event.addDomListener(window, 'load', initialize); 

moveend事件在google.maps V3中不再可用。请改用dragend

试试这个:

google.maps.event.addListener(map, "dragend", function() {
    var bounds = this.getBounds();
    onClickCallback(map);
});

我有同样的问题。

我在谷歌参考资料中找到了答案;

事件:空闲

参数:无

平移缩放后贴图变为空闲时,会触发此事件。

来自groops谷歌的一篇帖子。

google.mapsV3在整个地图上缺少一些重要的V2事件:

mousemove 
mouseover 
mouseout 
movebegin 
moveend 

看来bounds_changed可能会有所帮助。另请参阅用户destopero关于dragend的评论。