Answer the question
In order to leave comments, you need to log in
How to ignore the preferred language of the system, browser when requesting an API?
Hello, there is a code that determines the city by coordinates
if ("geolocation" in navigator) {
console.log('Доступно')
navigator.geolocation.getCurrentPosition(function(position) {
$.ajax({
url: "https://nominatim.openstreetmap.org/reverse",
data: {
lat: position.coords.latitude,
lon: position.coords.longitude,
format: "json"
},
beforeSend: function(xhr) {
xhr.setRequestHeader(
'User-Agent',
'ID of your APP/service/website/etc. v0.1'
)
},
dataType: "json",
type: "GET",
async: true,
crossDomain: true
}).done(function(res) {
if(document.querySelector('.city')){
document.querySelector('.city').innerHTML = res.address.city;
}
console.log(res.address)
console.log(res.address.city)
}).fail(function(error) {
console.error(error)
})
});
} else {
console.log('Не доступно');
document.querySelector('.city').innerHTML = 'Нет данных' ;
}
Answer the question
In order to leave comments, you need to log in
RTFM.
https://nominatim.org/release-docs/develop/api/Reverse/
Language of results
accept-language=<browser language string>
Preferred language order for showing search results, overrides the value specified in the "Accept-Language" HTTP header. Either use a standard RFC2616 accept-language string or a simple comma-separated list of language codes.
Or look at the API documentation, most likely there is a language parameter.
Or, as you have already been told, set the header with the language.
Option 1 is more correct, I think the second is more like a crutch.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question