简体   繁体   中英

Leaflet Providing invalid Lng/Lat coordinates when location duplicates on display

Question

Is the lng/lat provided by leaflet not a GPS coordinate? Do I have a way to convert it into GPS coordinates or is this a bug in leaflet?

Steps to reproduce

Setup a map that repeats. Click on the repeating section, the click event will return diffent and often invalid coordinates.

Expected behavior

The correct (repeated) coordinate would be provided for each GPS location, regardless if it repeats on the display.

Code to show error

Simply bind a click event

L.map(name, {fullscreenControl: true}).fitWorld().zoomIn().on("click", selectorConfirm);

function selectorConfirm = function(e) {
console.log('selected:'+e.latlng.lat+','+e.latlng.lng);
}

Minimal example reproducing the issue

https://www.hikerock.com/rock/210/

Click on map -> the console log will output what the gps coordinates are provided by leaflet.

The code is super simple, if you need to access it:

https://www.hikerock.com/plugin/map/js/map.min.js?cache=6x3cWuxp

function map() => inits leaflet map.prototype.selectorConfirm () -> is what is collects the event, is doing the console.logging

Looks like this is how Leaflet is designed:

https://github.com/Leaflet/Leaflet/issues/1885

It can be addressed by using:

e.latlng.wrap();
e.latlng.wrap().lat;

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