function getInfo() {
$.getJSON("get_info.php", function (data) {
for (var i = 0; i < data.length; i++) {
var location = new L.LatLng(data[i].lat, data[i].lng);
var marker = new L.Marker(location,{icon:Icon1});
marker.bindPopup(
data[i].name + "<br>" +
data[i].user_date + "<br>" +
data[i].user_time + "<br>" +
data[i].address + "<br>"
).addTo(map);
marker.on('click', function(e) { // HERE YOU GO
var ll = marker.getLatLng();
document.querySelector('#userLat').value = ll.lat;
document.querySelector('#userLng').value = ll.lng;
});
}
});
}
My code above works perfectly but I have one question. This will automatically generate marker in the map from database. I just wanna add a function that if the generated marker has been clicked it will show the markers lat/long in two diff textbox. how can i achieved this?
<text>Marker Latitude:<text>
<input id="userLat" type="text" name="userlat" />
<text>Marker Longhitude:<text><br>
<input id="userLng" type="text" name="userlng" /><br><br>