javascript - Moveend triggering in Google Maps - Stack Overflow

I am trying to add markers via Json once a visitor moves the map. For some reason the moveend is not ca

I am trying to add markers via Json once a visitor moves the map. For some reason the moveend is not caught and / or the function onClickCallback is not triggered. Where am I going wrong here.

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

 });


function onClickCallback(map) {

var bounds = map.getBounds();


  // clearOverlays();



    $.getJSON( '.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); 

I am trying to add markers via Json once a visitor moves the map. For some reason the moveend is not caught and / or the function onClickCallback is not triggered. Where am I going wrong here.

 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); 
Share Improve this question asked Dec 7, 2013 at 17:19 Mark HenryMark Henry 2,7097 gold badges40 silver badges49 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

The moveend event is no longer available in google.maps V3, use dragend instead.

Try this:

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

});

I have the same question.

I found the answer in google reference;

Event: idle

Arguments: None

This event is fired when the map bees idle after panning or zooming.

From one post at groops google.

google.maps V3 is missing some important V2 events on the whole map:

mousemove 
mouseover 
mouseout 
movebegin 
moveend 

It seems bounds_changed could help. See also ment from user sabotero about dragend.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742343906a4426160.html

相关推荐

  • javascript - Moveend triggering in Google Maps - Stack Overflow

    I am trying to add markers via Json once a visitor moves the map. For some reason the moveend is not ca

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信