Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pelias vs Google Maps
import axios from 'axios'
interface GeocodeFeature {
"type": "Feature",
"geometry": {
"type": string,
"coordinates": number[]
},
"properties": {
"label": string //full address we want to use
"layer": string
"name": string
"housenumber": string
"street": string
"confidence": number,
"match_type": string
"distance": number,
"accuracy": string
"country": string
"country_a": string
"region": string
"region_a": string
"county": string
"locality": string
"neighbourhood": string
"continent": string
}
}
interface GeocodeRes {
bbox: number[]
feature: GeocodeFeature
}
export function encodeHttpAuth(username: string, password: string) {
return 'Basic ' + Buffer.from(`${username}:${password}`).toString(
'base64'
)
}
export async function geocode(address: string, territory_bounds?: string): Promise<GeocodeRes> {
const baseUrl = `https://pelias-philadelphia.tryhabitat.com`
const urlEndpoint = `/v1/search?text=${encodeURIComponent(address)}`
//TODO: implement territory BBOX const options = '&boundary.rect.min_lat=25.84&boundary.rect.min_lon=-106.65&boundary.rect.max_lat=36.5&boundary.rect.max_lon=-93.51'
const request = `${baseUrl}${urlEndpoint}`
const { data: { bbox, features } } = await axios.post(request, {}, {
headers: {
'Authorization': encodeHttpAuth(
process.env.ENGINE_USERNAME,
process.env.ENGINE_PASSWORD
)
}
})
const res = { bbox, feature: features[0] }
return res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.