I place a Marker on my map with draggable property true. I want to restrict moving marker not more then 500 meters from original position. How can I do it? Is there a better way that I tried?
I tried with drag event. I measure distance with code I found on SO. But I don't know how can I prevent drag. I try with returning false, try to view if function parameter has cancel or something like that.
google.maps.event.addListener(marker, 'drag', function(e)
{
var distance = Application.getMapDistance(data[0].geometry.location, marker.getPosition());
document.title = distance;
if (distance > 500)
return false; //not working, e has no cancel or something like that
});
Edit:
Apparently someone is not happy with my question. Yes the basic logic would be to set google marker position to last good, but this way, marker flicker when it is moved outside the bounds. I am pretty sure Google can do better then this.
google.maps.event.addListener(marker, 'drag', function(e)
{
var distance = Application.getMapDistance(data[0].geometry.location, marker.getPosition());
document.title = distance;
if (distance > 500)
marker.setPosition(lastGoodPosition);
else
lastGoodPosition = marker.getPosition();
});