master: change repo
This commit is contained in:
32
src/services/MapService.ts
Normal file
32
src/services/MapService.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import ILocation from '@/models/ILocation'
|
||||
import ILocationQuery from '@/models/ILocationQuery'
|
||||
|
||||
class MapService {
|
||||
private key: string = process.env.VUE_APP_MAP_KEY || ''
|
||||
|
||||
public async getLocation(location: ILocation): Promise<string> {
|
||||
const result = await fetch(this.url(location.lat, location.lon))
|
||||
if (!result) {
|
||||
return ''
|
||||
}
|
||||
const json: ILocationQuery = await result.json()
|
||||
if (
|
||||
!json ||
|
||||
!json.resourceSets ||
|
||||
!json.resourceSets.length ||
|
||||
!json.resourceSets[0].resources.length
|
||||
) {
|
||||
return ''
|
||||
}
|
||||
const address = json.resourceSets[0].resources[0].address
|
||||
return address ? address.locality : ''
|
||||
}
|
||||
|
||||
private url(latitude: number, longitude: number) {
|
||||
return `https://dev.virtualearth.net/REST/v1/Locations/${latitude},${longitude}?key=${
|
||||
this.key
|
||||
}`
|
||||
}
|
||||
}
|
||||
|
||||
export default new MapService()
|
||||
Reference in New Issue
Block a user