Reputation: 29
I'm using Geolocation on my map and I can't figure out how to set the zoom level when gelocation is found. My code looks like this:
if (!navigator.geolocation) {
geolocate.innerHTML = 'Geolocation is not available';
} else {
geolocate.onclick = function (e) {
var tl = new TimelineMax({repeat:2});
tl.to("svg.pointwhite", .10, {transformOrigin: "50% 100%", scaleY:0.25, yoyo:true, repeat:1})
.to("svg.pointwhite", .65, {y:-6, ease:Circ.easeOut, yoyo:true, repeat:1});
e.preventDefault();
e.stopPropagation();
map.locate();
};
}
Is it inside the map.locate
you set the zoom level? I have tried it of course and failed. As always, I really appreciate any help you guys can provide.
Upvotes: 1
Views: 499
Reputation: 306
When using Leaflet I use map.setView()
. Here is my Leaflet navigator code:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
latlng: {lat:position.coords.latitude,lng:position.coords.longitude},
lat:position.coords.latitude,
lng:position.coords.longitude
};
addMarker(pos);
map.setView(L.latLng(pos.lat, pos.lng),13);
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
Upvotes: 1