geo-city-finder
Version:
A lightweight JavaScript library for identifying cities based on geographical coordinates and determining if provided coordinates match those of a city with high accuracy.
25 lines (24 loc) • 936 B
JavaScript
const u = 2546.076925492267, d = (t, o, n) => {
const c = h(t.latitude, t.longitude, o.latitude, o.longitude), a = t.accuracy + o.accuracy + n;
return c <= a;
}, h = (t, o, n, c) => {
const s = i(n - t), r = i(c - o), e = Math.sin(s / 2) * Math.sin(s / 2) + Math.cos(i(t)) * Math.cos(i(n)) * Math.sin(r / 2) * Math.sin(r / 2);
return 6371 * (2 * Math.atan2(Math.sqrt(e), Math.sqrt(1 - e)));
}, i = (t) => t * (Math.PI / 180);
function M(t) {
return new Promise((o) => {
navigator.geolocation || (console.log("Geolocation is not supported by this browser."), o(void 0)), navigator.geolocation.getCurrentPosition((n) => {
const { latitude: c, longitude: a, accuracy: s } = n.coords, e = d({
latitude: c,
longitude: a,
accuracy: s
}, t, u);
o(e);
}, (n) => {
console.error("Error getting geolocation:", n), o(void 0);
});
});
}
export {
M as getCoordinatesMatch
};