Created
April 22, 2015 02:46
-
-
Save hanislovingit/b745e1b17a5a4fb15146 to your computer and use it in GitHub Desktop.
Mapbox-creation-api-map-locate
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
// try to locate the user | |
map.locate(); | |
// handle location found | |
map.on('locationfound', function (e) { | |
// add a circle marker having the center at the location | |
L.circleMarker(e.latlng) | |
.setRadius(200) | |
.addTo(map); | |
// add some padding and move the map view to the user's location | |
var padding = Math.max(map.getSize().x, map.getSize().y) * 0.1; | |
map.fitBounds(e.bounds, { | |
animate: true, | |
padding: [padding, padding] | |
}); | |
}); | |
// handle location not found or error | |
map.on('locationerror', function (data) { }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment