Skip to content Skip to sidebar Skip to footer

Alerts Are Not Showing In Geofencing When Marker Is Outside Of Polygon Geofence In Google Maps

i have code for geofencing , in that polygon shape is there while dragging one marker out side the polygon its giving alert , but i need it should give alert automatically when pag

Solution 1:

I think this should do it. All the Gmaps.js is doing under the hood is

if (marker.fences) {
    google.maps.event.addListener(marker, 'dragend', function() {
      self.checkMarkerGeofence(marker, function(m, f) {
        outside(m, f);
      });
    });
}

https://github.com/hpneo/gmaps/blob/master/gmaps.js#L851

So assign your markers to variables. On load, trigger the 'dragend' event on each of them:

var marker1 = map.addMarker({
    lat: -12.043333,
    lng: -77.028333,
    draggable: true,
    fences: [polygon],
    outside: function (marker, fence) {
        alert('This marker has been moved outside of its fence');
    }
});

var marker2 = map.addMarker({
    lat: -12.041111,
    lng: -77.021111,
    draggable: true,
    fences: [polygon],
    outside: function (marker, fence) {
        alert('This marker has been moved outside of its fence');
    }
});

google.maps.event.trigger(marker1, 'dragend');
google.maps.event.trigger(marker2, 'dragend');

Post a Comment for "Alerts Are Not Showing In Geofencing When Marker Is Outside Of Polygon Geofence In Google Maps"