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:
xenDE 2019-12-29 14:57:17 +01:00 committed by GitHub
parent c300e73726
commit 4164e7c067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -270,5 +270,16 @@
positionsLoaded = true;
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>
</body></html>