60 lines
No EOL
2 KiB
JavaScript
60 lines
No EOL
2 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);
|
|
if(l === undefined){
|
|
return await place1(lng,lat);
|
|
} else {
|
|
if(l.county_code === undefined){
|
|
const l1 = await place1(lng,lat);
|
|
if(l1 === undefined){ } else {
|
|
l.county_code = l1.province_code.split("-")[1];
|
|
}
|
|
}
|
|
return l;
|
|
}
|
|
}
|
|
|
|
|
|
async function place(lng,lat) {
|
|
const myAPIKey = "6dc7fb95a3b246cfa0f3bcef5ce9ed9a";
|
|
const reverseGeocodingUrl = `https://api.geoapify1.com/v1/geocode/reverse?lat=${lat}&lon=${lng}&apiKey=${myAPIKey}`
|
|
//console.log(reverseGeocodingUrl);
|
|
try {
|
|
const f = await axios.get(reverseGeocodingUrl);
|
|
if(f.status == 200){
|
|
const k = f.data.features[0].properties;
|
|
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 }
|
|
} else {
|
|
//console.log("errore1a");
|
|
return undefined;
|
|
}
|
|
} catch (error) {
|
|
//console.log("errore1b");
|
|
return undefined;
|
|
}
|
|
|
|
}
|
|
|
|
async function place1(lng,lat){
|
|
try {
|
|
const loc = await axios.get('http://192.168.1.3:6565/query?'+lng+'&'+lat);
|
|
const k = loc.data
|
|
//console.log(loc);
|
|
return {continent: k.region,country: k.country, region: undefined, postcode: undefined, city: undefined, county_code: k.province_code.split("-")[1], address: undefined, timezone: undefined, time: undefined };
|
|
} catch (error) {
|
|
//console.log("errore2");
|
|
return undefined;
|
|
}
|
|
} |