updated to proxy loaction search from museum
This commit is contained in:
parent
ccfcc74299
commit
bc044800ae
|
@ -126,7 +126,7 @@ export default function SearchBar(props: Props) {
|
|||
({
|
||||
type: SuggestionType.LOCATION,
|
||||
value: searchResult.bbox,
|
||||
label: searchResult.placeName,
|
||||
label: searchResult.place,
|
||||
} as Suggestion)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import HTTPService from './HTTPService';
|
||||
import * as chrono from 'chrono-node';
|
||||
import { getEndpoint } from 'utils/common/apiUtil';
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
|
||||
const KM_IN_DEGREE = 0.01;
|
||||
export type Bbox = [number, number, number, number];
|
||||
export interface LocationSearchResponse {
|
||||
placeName: string;
|
||||
place: string;
|
||||
bbox: Bbox;
|
||||
}
|
||||
export const getMapboxToken = () => {
|
||||
|
@ -16,26 +18,11 @@ export function parseHumanDate(humanDate: string) {
|
|||
}
|
||||
|
||||
export async function searchLocation(
|
||||
location: string
|
||||
searchPhrase: string
|
||||
): Promise<LocationSearchResponse[]> {
|
||||
const resp = await HTTPService.get(
|
||||
`https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURI(
|
||||
location
|
||||
)}.json`,
|
||||
{ access_token: getMapboxToken(), limit: 4 }
|
||||
);
|
||||
|
||||
return resp.data.features.length == 0
|
||||
? new Array<LocationSearchResponse>()
|
||||
: resp.data.features.map((feature) => ({
|
||||
placeName: feature.place_name,
|
||||
bbox:
|
||||
feature.bbox ??
|
||||
([
|
||||
feature.center[0] - KM_IN_DEGREE,
|
||||
feature.center[1] - KM_IN_DEGREE,
|
||||
feature.center[0] + KM_IN_DEGREE,
|
||||
feature.center[1] + KM_IN_DEGREE,
|
||||
] as Bbox),
|
||||
}));
|
||||
const resp = await HTTPService.get(`${ENDPOINT}/search/location`, {
|
||||
query: searchPhrase,
|
||||
limit: 4,
|
||||
});
|
||||
return resp.data;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue