I have been doing leaflet API since 2 days. I have been stuck in a function call which gives me unexpected behaviour. the code is as follows
var it=0;
var map = L.map('map1', {
center:[51.505,-0.09],
zoom: 2,
});
L.tileLayer('http://{s}.tile.cloudmade.com/c77b2fb7bfb74f74998061abda20d58f/997/256/{z}/{x}/{y}.png',{
attribution: '2013 © @ Rajat/Akshat',
maxZoom: 18
}).addTo(map);
var marker = L.marker([51.5,-0.09], {draggable: true, opacity: 0.8}).addTo(map);
function onDragEnd(e) {
var lat_marker = e.target._latlng.lat;
var lng_marker = e.target._latlng.lng;
}
var i=6;
marker.on('dragend',onDragEnd(event));
The map1 div
id has been created on HTML page.
Now the problem is this function:
marker.on('dragend',onDragEnd(event));
It shows this error
ReferenceError: event is not defined
marker.on('dragend',onDragEnd(event));
But when I pass it without any argument marker.on('dragend',onDragEnd());
, it works.
Also, I want to add my own parameter in the function:
marker.on('dragend',onDragEnd(i));
Where i
is some simple variable. But something is wrong in this function, it doesn't work as expected.