Leaflet knn (nearest element) and user location : browser autorisation

المشرف العام

Administrator
طاقم الإدارة
I'm using leaflet-knn to search the nearest geojson element from the user location. Basically it show a feature property (the city name of the element in this case), but i want to add an animation that zoom to the user location. I try map.locate method but the web browser asking for the location authorisation twice.

Can i avoid the browser requesting the location permission twice?

Here is the code

var gjLayer = L.geoJson(geoJsonData); document.getElementById('button').onclick = function() {navigator.geolocation.getCurrentPosition(function(pos){ var res = leafletKnn(gjLayer).nearest( [pos.coords.longitude, pos.coords.latitude], 1); if (res.length) { document.getElementById('button').innerHTML = 'The nearest element is at '+ res[0].layer.feature.properties.cityname; map.locate({setView: true}); } else { document.getElementById('button').innerHTML = 'error'; } }); };

أكثر...
 
أعلى