54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
import {returnOnError} from "../utilities/reporterror.js"
|
|
import axios from 'axios'
|
|
import {logit} from "../utilities/logit.js"
|
|
import {getOneProperty} from "./getproperties.js"
|
|
|
|
const NOMINATIM_URL = `https://nominatim.openstreetmap.org/reverse?lat=${'xx'}&lon=${'yy'}&format=json`
|
|
|
|
export const getAddress = async (params) => {
|
|
let ret = {address: "", err: null}
|
|
let {props, err} = await getOneProperty(params)
|
|
if (err) {
|
|
return returnOnError(ret, err, getAddress.name)
|
|
}
|
|
let coord = props.location[0].loc.coordinates
|
|
let url = NOMINATIM_URL.replace('xx', coord[1]).replace('yy', coord[0])
|
|
try {
|
|
const response = await axios(encodeURI(url));
|
|
if (response.status !== 200) {
|
|
return returnOnError(ret, 'RESPSTATUS', getAddress.name, response.status)
|
|
}
|
|
let akt = response.data.address
|
|
logit(JSON.stringify(akt))
|
|
const CITY = ['city', 'town', 'village', 'suburb', 'county']
|
|
let city = "unknown"
|
|
for (let c of CITY) {
|
|
if(akt[c] !== undefined) {
|
|
city = akt[c]
|
|
break
|
|
}
|
|
}
|
|
ret.address = `${(akt.road ? akt.road : "")} ${(akt.postcode ? akt.postcode : "")} ${city}`;
|
|
} catch (e) {
|
|
return returnOnError(ret, e, getAddress.name)
|
|
}
|
|
return ret
|
|
}
|
|
/*
|
|
let addr = "Addr";
|
|
try {
|
|
let ret = await $.get("api/getprops?sensorid=" + marker.options.name);
|
|
if(ret.values[0].address.city == null) {
|
|
addr += " unbekannt !"
|
|
} else {
|
|
let akt = ret.values[0].address;
|
|
addr = (akt.street ? akt.street : "") + " " + (akt.plz ? akt.plz : "") + " " + akt.city;
|
|
}
|
|
} catch (e) {
|
|
console.log("onMarker - getpops", e)
|
|
}
|
|
console.log("addr:", addr);
|
|
return addr;
|
|
|
|
*/
|