Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moveend triggering in Google Maps

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); 
like image 296
Mark Henry Avatar asked Mar 29 '26 23:03

Mark Henry


1 Answers

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);

});
like image 104
sabotero Avatar answered Apr 02 '26 16:04

sabotero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!