✨ (transaction) possibility to change location
This commit is contained in:
@@ -4,7 +4,25 @@ import ILocationQuery from '@/models/ILocationQuery'
|
||||
class MapService {
|
||||
private key: string = process.env.VUE_APP_MAP_KEY || ''
|
||||
|
||||
public async getLocation(location: ILocation): Promise<string> {
|
||||
public async getPosition(): Promise<ILocation | null> {
|
||||
const position = await this.getCurrentPosition()
|
||||
if (!position) {
|
||||
return null
|
||||
}
|
||||
const { coords } = position
|
||||
const location = {
|
||||
lat: coords.latitude,
|
||||
lon: coords.longitude
|
||||
}
|
||||
const place = await this.getPlace(location)
|
||||
|
||||
return {
|
||||
...location,
|
||||
place
|
||||
}
|
||||
}
|
||||
|
||||
public async getPlace(location: ILocation): Promise<string> {
|
||||
const result = await fetch(this.url(location.lat, location.lon))
|
||||
if (!result) {
|
||||
return ''
|
||||
@@ -25,6 +43,15 @@ class MapService {
|
||||
private url(latitude: number, longitude: number) {
|
||||
return `https://dev.virtualearth.net/REST/v1/Locations/${latitude},${longitude}?key=${this.key}`
|
||||
}
|
||||
|
||||
private getCurrentPosition(): Promise<Position | null> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!('geolocation' in navigator)) {
|
||||
resolve(null)
|
||||
}
|
||||
return navigator.geolocation.getCurrentPosition(resolve, reject)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new MapService()
|
||||
|
||||
Reference in New Issue
Block a user