A Pen by Max Dolgov on CodePen.
Created
April 29, 2015 17:34
-
-
Save plugn/3159877bb09f460d6ff3 to your computer and use it in GitHub Desktop.
LGeoTracker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="map"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map { | |
height: 400px; | |
background-color: #ddd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment