Skip to content

Commit

Permalink
geolocator_add
Browse files Browse the repository at this point in the history
  • Loading branch information
MandenB committed May 12, 2024
1 parent 523b6c9 commit e094ef0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lab5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@ register_geocoder = function (mapInstance) {
}

register_geocoder(map)

function registerGeoLocate(mapInstance) {
mapInstance.locate({ setView: true, maxZoom: 16 });

function onLocationFound(e) {
var radius = e.accuracy;

let m = L.marker(e.latlng).addTo(map)
.bindPopup("You are within " + radius.toFixed(1) + " meters from this point").openPopup();

let c = L.circle(e.latlng, radius).addTo(map);

setTimeout(function () {
mapInstance.removeLayer(m);
mapInstance.removeLayer(c);
},
25000);
}

mapInstance.on('locationfound', onLocationFound);

function onLocationError(e) {
alert(e.message);
}

mapInstance.on('locationerror', onLocationError);
}
registerGeoLocate(map)

0 comments on commit e094ef0

Please sign in to comment.