webgpsmap: get current position and set marker on map in interval (30s)
used the browsers geolocation function to get the current location, show a marker and center the map there. on success (user allows usage of get-current-position) it gets position every 30s and reposition the marker without center the map to the marker.
This commit is contained in:
parent
c300e73726
commit
4164e7c067
@ -270,5 +270,16 @@
|
|||||||
positionsLoaded = true;
|
positionsLoaded = true;
|
||||||
drawPositions();
|
drawPositions();
|
||||||
});
|
});
|
||||||
|
// get current position and set marker in interval
|
||||||
|
var myLocationMarker = {};
|
||||||
|
function onLocationFound(e) {
|
||||||
|
if (myLocationMarker != undefined) {
|
||||||
|
mymap.removeLayer(myLocationMarker);
|
||||||
|
};
|
||||||
|
myLocationMarker = L.marker(e.latlng).addTo(mymap);
|
||||||
|
setTimeout(function(){ mymap.locate(); }, 30000);
|
||||||
|
}
|
||||||
|
mymap.on('locationfound', onLocationFound);
|
||||||
|
mymap.locate({setView: true});
|
||||||
</script>
|
</script>
|
||||||
</body></html>
|
</body></html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user