From 6256c71c685c1ef16f45b6c803c497802221494e Mon Sep 17 00:00:00 2001 From: strukturart Date: Wed, 19 Jun 2024 00:25:31 +0200 Subject: [PATCH] what3words --- application/assets/js/module.js | 28 +++++++++++++++++++++++++++- application/index.html | 7 +++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/application/assets/js/module.js b/application/assets/js/module.js index 19ae0400..8eff4130 100644 --- a/application/assets/js/module.js +++ b/application/assets/js/module.js @@ -424,7 +424,14 @@ const module = (() => { //show selected marker map.setView(markers_collection[index].getLatLng()); - console.log(markers_collection[index]); + + let marker_latlng = markers_collection[index].getLatLng(); + + what3words(marker_latlng.lat, marker_latlng.lng, "76YHEAE5").then( + (what3wordsAddress) => { + document.querySelector("#what3words").textContent = what3wordsAddress; + } + ); //popup document.querySelector("input#popup").value = ""; @@ -1237,6 +1244,24 @@ const module = (() => { return a.toFixed(2); }; + let what3words = (lat, lng, key) => { + const url = `https://api.what3words.com/v3/convert-to-3wa?coordinates=${lat},${lng}&key=${key}`; + + return fetch(url) + .then((response) => response.json()) + .then((data) => { + if (data.words) { + return data.words; + } else { + throw new Error(data); + } + }) + .catch((error) => { + console.error("Error:", error); + return null; + }); + }; + return { hotline, convert_units, @@ -1262,5 +1287,6 @@ const module = (() => { uniqueId, parseGPX, update_gpx_info, + what3words, }; })(); diff --git a/application/index.html b/application/index.html index 720c264b..44e2f678 100644 --- a/application/index.html +++ b/application/index.html @@ -121,6 +121,13 @@ remove marker +

What3words

+
+ + + + +

Routing

set as start point