I am using leaflet js to draw a map. I am struggling in situation where i want to get latitude, longitude & zoom level of map on two events first is zoom and second in on click. I have search a stack's post : Get Position on zooming in map : leaflet but no help is found. At first i have tried to get lat & lng first but i get southwest & northeast meta data how can i get a perfect lat & lng.
var map = L.map('map').setView([51.505, -0.09], 13);
var tiles = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
}).addTo(map);
// first i try the on zoomend event to get lat, lng
map.on('zoomend',function(e){
var map = e.target,
bounds = map.getBounds();
// here i get southwest & northeast data how to get lat & lng & zoom level
console.log(bounds);
})
<!-- required js & css -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<!-- in it i draw map -->
<div id="map" style="height:400px; width:900px"></div>