Skip to content

Instantly share code, notes, and snippets.

@hanislovingit
Created April 22, 2015 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanislovingit/b745e1b17a5a4fb15146 to your computer and use it in GitHub Desktop.
Save hanislovingit/b745e1b17a5a4fb15146 to your computer and use it in GitHub Desktop.
Mapbox-creation-api-map-locate
// 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