mirror of
https://gitlab.com/little-lines/frontend.git
synced 2024-11-24 11:26:52 +00:00
feature: add user location
This commit is contained in:
parent
82e1e4e86a
commit
e2075b96d4
1 changed files with 28 additions and 1 deletions
|
@ -104,6 +104,7 @@
|
|||
background-color: rgba(230, 230, 230, 1);
|
||||
padding-left: 2vw;"
|
||||
variant="invert-solo"
|
||||
:model-value="formattedLocation"
|
||||
flat
|
||||
></v-text-field>
|
||||
<v-btn
|
||||
|
@ -238,13 +239,20 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
showPopup: true,
|
||||
showRoute: false
|
||||
showRoute: false,
|
||||
userLocation: null
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
cardHeight() {
|
||||
return this.showRoute ? '45vh' : '60vh';
|
||||
},
|
||||
formattedLocation() {
|
||||
if (this.userLocation) {
|
||||
return `${this.userLocation.lat.toFixed(6)}, ${this.userLocation.lon.toFixed(6)}`;
|
||||
}
|
||||
return 'Location not available';
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
closePopup() {
|
||||
|
@ -252,8 +260,27 @@ export default {
|
|||
this.onClose();
|
||||
},
|
||||
viewRoute() {
|
||||
this.getUserLocation();
|
||||
this.showRoute = true;
|
||||
},
|
||||
getUserLocation() {
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(this.setLocation, this.handleLocationError);
|
||||
} else {
|
||||
console.error("Geolocation is not supported by this browser.");
|
||||
}
|
||||
},
|
||||
setLocation(position) {
|
||||
this.userLocation = {
|
||||
lat: position.coords.latitude,
|
||||
lon: position.coords.longitude
|
||||
};
|
||||
console.log('User Location:', this.userLocation);
|
||||
},
|
||||
|
||||
handleLocationError(error) {
|
||||
console.error('Error getting location:', error);
|
||||
},
|
||||
viewPopup(){
|
||||
this.showPopup = true;
|
||||
this.showRoute = false;
|
||||
|
|
Loading…
Reference in a new issue