/
mapbox.ts
48 lines (42 loc) · 943 Bytes
/
mapbox.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import axios from "axios";
const networking = axios.create({
baseURL: "https://api.mapbox.com/geocoding/v5/mapbox.places",
});
export const queryPlaces = async (query: string): Promise<Array<Location>> => {
const resp = await networking.get(`/${query}.json`, {
params: {
types: "poi",
access_token: process.env.NEXT_PUBLIC_MAPBOX_API,
},
});
return resp.data.features;
};
// Mapbox types
export interface Location {
id: string;
type: string;
place_type: string[];
relevance: number;
properties: Properties;
text: string;
place_name: string;
center: number[];
geometry: Geometry;
context: Context[];
}
export interface Context {
id: string;
text: string;
wikidata?: string;
short_code?: string;
}
export interface Geometry {
coordinates: number[];
type: string;
}
export interface Properties {
foursquare: string;
landmark: boolean;
address: string;
category: string;
}