Skip to content

Instantly share code, notes, and snippets.

@plugn
Created April 29, 2015 17:34
Show Gist options
  • Save plugn/3159877bb09f460d6ff3 to your computer and use it in GitHub Desktop.
Save plugn/3159877bb09f460d6ff3 to your computer and use it in GitHub Desktop.
LGeoTracker
<div id="map"></div>
var
map,
marker,
tiles = 'http://tiles.maps.sputnik.ru/tiles/kmt2/{z}/{x}/{y}.png';
function init() {
console.log('init()');
map = L.map('map');
// marker = L.marker(map.getCenter()).addTo(map);
// .setView([55.75, 37.6167], 9);
L.tileLayer(tiles, {
minZoom: 3,
maxZoom: 18
})
.addTo(map);
map.locate({
watch: true,
setView: true,
maxZoom: 16,
enableHighAccuracy: true
// maximumAge: 1000
})
map.on('locationfound', function(e){
console.log('found ', e);
if (! marker) {
marker = L.marker(e.latlng);
map.addLayer(marker);
}
else {
marker.setLatLng(e.latlng);
}
});
}
init();
#map {
height: 400px;
background-color: #ddd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment