refactor(map): switch reverse geocoding from Bing to Mapbox
Reuse the existing Mapbox token instead of maintaining a separate Bing Maps key. Note the coordinate order flips to lon,lat for the Mapbox geocoding endpoint.
This commit is contained in:
@@ -2,7 +2,7 @@ import ILocation from '@/models/ILocation'
|
||||
import ILocationQuery from '@/models/ILocationQuery'
|
||||
|
||||
class MapService {
|
||||
private key: string = import.meta.env.VITE_MAP_KEY || ''
|
||||
private token: string = import.meta.env.VITE_MAPBOX_KEY || ''
|
||||
|
||||
public async getPosition(): Promise<ILocation | null> {
|
||||
const position = await this.getCurrentPosition()
|
||||
@@ -28,20 +28,11 @@ class MapService {
|
||||
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 : ''
|
||||
return json?.features?.[0]?.text ?? ''
|
||||
}
|
||||
|
||||
private url(latitude: number, longitude: number) {
|
||||
return `https://dev.virtualearth.net/REST/v1/Locations/${latitude},${longitude}?key=${this.key}`
|
||||
return `https://api.mapbox.com/geocoding/v5/mapbox.places/${longitude},${latitude}.json?types=place&limit=1&access_token=${this.token}`
|
||||
}
|
||||
|
||||
private getCurrentPosition(): Promise<GeolocationPosition | null> {
|
||||
|
||||
Reference in New Issue
Block a user