简体   繁体   中英

find latitude & longitude of saved marker in leaflet

I have circle marker

var myMarker = L.circleMarker(stuSplit, 
    { title: 'unselected' })
        .bindLabel("Name: " + students[i][j][0] 
                   + " ReachTime: " + students[i][j][2]);

Now I want to find latitude & Longitude this myMarker.

I was trying myMarker.getLatLng() but it is not working.

The problem does not lie in getLatLng(). This works fine:

var map = L.map('map').setView([55.4411764, 11.7928708], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var stuSplit = L.latLng(55.4411764, 11.7928708);
var myMarker = L.circleMarker(stuSplit, 
    { title: 'unselected' })
        .addTo(map);
alert(myMarker.getLatLng());

See a working example here:

http://jsfiddle.net/pX2xn/2/

So you can

$("#One").click(function(){
    var curPos = myMarker.getLatLng();
    alert(curPos.lng + " : " + curPos.lat);
});

this in more detail.

See a working example here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM