leaflet version : 2.2.1
Hi
How can i get current location ? sorry i didn't find an example for this.
@Mateo111001 You can use the leaflet location function, keep in mind you can always access any leaflet function trough the mapObject property on LMap or any other component. about locate you can do as follows:
<l-map @ready="onReady" ... @locationfound="onLocationFound" .../>
methods: {
onReady (mapObject) {
mapObject.locate();
},
onLocationFound(location){
console.log(location)
}
}
for all the options and return format please follow: https://leafletjs.com/reference-1.6.0.html#map-locate
This would be an awesome addition to our faq? would you like to make a PR with it? :)
I wanted to show a full example of what worked for me, showing a circle with my location onLocationFound and the radius with a semi-transparent background (simulating google maps)
<template>
<l-map @ready="onReady" ref="map" @locationfound="onLocationFound">
<template v-if="location">
<l-circle-marker :lat-lng="location.latlng" :fillOpacity="1" :radius="0.1" />
<l-circle-marker :lat-lng="location.latlng" :radius="location.accuracy/2" :stroke="false" />
</template>
</l-map>
<script>
export default {
data() {
map: null,
location: null
},
methods: {
onReady() {
this.map = this.$refs["map"].mapObject;
this.map.locate();
},
onLocationFound(l) {
console.log(l);
this.location = l;
},
}
</script>
Most helpful comment
@Mateo111001 You can use the leaflet location function, keep in mind you can always access any leaflet function trough the
mapObjectproperty onLMapor any other component. about locate you can do as follows:for all the options and return format please follow: https://leafletjs.com/reference-1.6.0.html#map-locate
This would be an awesome addition to our faq? would you like to make a PR with it? :)