refactor(util): Verschieben von Methoden über Standort nach util.location.js.
This commit is contained in:
@@ -1,50 +1,5 @@
|
|||||||
const B64ToBuff = (base64String) => new Uint8Array(Array.from(atob(base64String), char => char.charCodeAt(0))).buffer;
|
const B64ToBuff = (base64String) => new Uint8Array(Array.from(atob(base64String), char => char.charCodeAt(0))).buffer;
|
||||||
|
|
||||||
function getCoordinates() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (navigator.geolocation) {
|
|
||||||
navigator.geolocation.getCurrentPosition(
|
|
||||||
position => resolve(position.coords),
|
|
||||||
error => reject(error)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
reject(new Error("Geolocation is not supported by this browser."));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getCity() {
|
|
||||||
try {
|
|
||||||
const coords = await getCoordinates();
|
|
||||||
const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`);
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
if (data && data.address) {
|
|
||||||
const city = data.address.city || data.address.town || data.address.village || data.address.hamlet;
|
|
||||||
const postalCode = data.address.postcode;
|
|
||||||
return postalCode + ' ' + city || '';
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getLocation() {
|
|
||||||
try {
|
|
||||||
const coords = await getCoordinates();
|
|
||||||
const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`);
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
if (data && data.address) {
|
|
||||||
const city = data.address.city || data.address.town || data.address.village || data.address.hamlet;
|
|
||||||
const postalCode = data.address.postcode;
|
|
||||||
return { postalCode: postalCode, city: city };
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return { postalCode: '', city: '' };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getLocaleDateString = _ => new Date().toLocaleDateString('de-DE')
|
const getLocaleDateString = _ => new Date().toLocaleDateString('de-DE')
|
||||||
|
|
||||||
function detailedCurrentDate() {
|
function detailedCurrentDate() {
|
||||||
|
|||||||
44
EnvelopeGenerator.Web/wwwroot/js/util.location.js
Normal file
44
EnvelopeGenerator.Web/wwwroot/js/util.location.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
function getCoordinates() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (navigator.geolocation) {
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
position => resolve(position.coords),
|
||||||
|
error => reject(error)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
reject(new Error("Geolocation is not supported by this browser."));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCity() {
|
||||||
|
try {
|
||||||
|
const coords = await getCoordinates();
|
||||||
|
const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`);
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data && data.address) {
|
||||||
|
const city = data.address.city || data.address.town || data.address.village || data.address.hamlet;
|
||||||
|
const postalCode = data.address.postcode;
|
||||||
|
return postalCode + ' ' + city || '';
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLocation() {
|
||||||
|
try {
|
||||||
|
const coords = await getCoordinates();
|
||||||
|
const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`);
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data && data.address) {
|
||||||
|
const city = data.address.city || data.address.town || data.address.village || data.address.hamlet;
|
||||||
|
const postalCode = data.address.postcode;
|
||||||
|
return { postalCode: postalCode, city: city };
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return { postalCode: '', city: '' };
|
||||||
|
}
|
||||||
|
}
|
||||||
2
EnvelopeGenerator.Web/wwwroot/js/util.min.js
vendored
2
EnvelopeGenerator.Web/wwwroot/js/util.min.js
vendored
@@ -1 +1 @@
|
|||||||
function getCoordinates(){return new Promise((n,t)=>{navigator.geolocation?navigator.geolocation.getCurrentPosition(t=>n(t.coords),n=>t(n)):t(new Error("Geolocation is not supported by this browser."))})}async function getCity(){try{const t=await getCoordinates(),i=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${t.latitude}&lon=${t.longitude}`),n=await i.json();if(n&&n.address){const t=n.address.city||n.address.town||n.address.village||n.address.hamlet,i=n.address.postcode;return i+" "+t||""}}catch{return""}}async function getLocation(){try{const t=await getCoordinates(),i=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${t.latitude}&lon=${t.longitude}`),n=await i.json();if(n&&n.address){const t=n.address.city||n.address.town||n.address.village||n.address.hamlet,i=n.address.postcode;return{postalCode:i,city:t}}}catch{return{postalCode:"",city:""}}}function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer;const getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE");
|
function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer,getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE");
|
||||||
Reference in New Issue
Block a user