@@ -11,6 +11,7 @@ import {
1111 useRef ,
1212 useState ,
1313} from "react" ;
14+ import { useTranslation } from "react-i18next" ;
1415import { service } from "service" ;
1516import {
1617 filterDuplicatePlaces ,
@@ -85,6 +86,9 @@ const NOMINATIM_URL = process.env.NEXT_PUBLIC_NOMINATIM_URL;
8586
8687const useGeocodeQuery = ( ) => {
8788 const isMounted = useIsMounted ( ) ;
89+ const {
90+ i18n : { languages : locales } ,
91+ } = useTranslation ( ) ;
8892 const [ isLoading , setIsLoading ] = useSafeState ( isMounted , false ) ;
8993 const [ error , setError ] = useSafeState < string | undefined > (
9094 isMounted ,
@@ -103,9 +107,16 @@ const useGeocodeQuery = () => {
103107 setIsLoading ( true ) ;
104108 setError ( undefined ) ;
105109 setResults ( undefined ) ;
106- const url = `${ NOMINATIM_URL ! } search?format=jsonv2&q=${ encodeURIComponent (
107- value ,
108- ) } &addressdetails=1`;
110+
111+ // Refer to https://nominatim.org/release-docs/latest/api/Search/
112+ const queryArgs = new URLSearchParams ( {
113+ format : "jsonv2" ,
114+ q : value ,
115+ addressdetails : "1" , // include a breakdown of the address into elements
116+ "accept-language" : locales . join ( "," ) ,
117+ } ) ;
118+
119+ const url = `${ NOMINATIM_URL ! } search?${ queryArgs } ` ;
109120 const fetchOptions = {
110121 headers : {
111122 Accept : "application/json" ,
@@ -160,7 +171,7 @@ const useGeocodeQuery = () => {
160171 }
161172 setIsLoading ( false ) ;
162173 } ,
163- [ setError , setIsLoading , setResults ] ,
174+ [ locales , setError , setIsLoading , setResults ] ,
164175 ) ;
165176
166177 return { isLoading, error, results, query } ;
0 commit comments