updated to proxy loaction search from museum

This commit is contained in:
Abhinav-grd 2021-05-26 15:48:13 +05:30
parent ccfcc74299
commit bc044800ae
2 changed files with 11 additions and 24 deletions

View file

@ -126,7 +126,7 @@ export default function SearchBar(props: Props) {
({
type: SuggestionType.LOCATION,
value: searchResult.bbox,
label: searchResult.placeName,
label: searchResult.place,
} as Suggestion)
)
);

View file

@ -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;
}