39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
run();
|
|
|
|
async function run(){
|
|
var a = await loc(12.082978,44.250746);
|
|
console.log(a);
|
|
}
|
|
|
|
|
|
async function loc(lng,lat){
|
|
const l = await place(lng,lat);
|
|
return l;
|
|
}
|
|
|
|
|
|
async function place(lng,lat) {
|
|
const reverseGeocodingUrl = 'https://nominatim.openstreetmap.org/reverse?lat='+lat+'&lon='+lng+'&format=jsonv2';
|
|
//console.log(reverseGeocodingUrl);
|
|
try {
|
|
const f = await axios.get(reverseGeocodingUrl);
|
|
if(f.status == 200){
|
|
const k = f.data.address;
|
|
//return {continent: k.timezone.name.split("/")[0],country: k.country, region: k.state, postcode: k.postcode, city: k.city, county_code: k.county_code, address: k.address_line1, timezone: k.timezone.name, time: k.timezone.offset_STD }
|
|
return k;
|
|
} else {
|
|
//console.log("errore1a");
|
|
return undefined;
|
|
}
|
|
} catch (error) {
|
|
//console.log("errore1b");
|
|
return undefined;
|
|
}
|
|
|
|
}
|
|
|