diff --git a/src/components/SearchBar.tsx b/src/components/SearchBar.tsx index 56b4433c0..6dd91a494 100644 --- a/src/components/SearchBar.tsx +++ b/src/components/SearchBar.tsx @@ -126,7 +126,7 @@ export default function SearchBar(props: Props) { ({ type: SuggestionType.LOCATION, value: searchResult.bbox, - label: searchResult.placeName, + label: searchResult.place, } as Suggestion) ) ); diff --git a/src/services/searchService.ts b/src/services/searchService.ts index 6cbf02130..70de4712d 100644 --- a/src/services/searchService.ts +++ b/src/services/searchService.ts @@ -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 { - 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() - : 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; }