Skip to content

Commit

Permalink
what3words
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Jun 18, 2024
1 parent 0d7de1b commit 6256c71
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
28 changes: 27 additions & 1 deletion application/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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,
Expand All @@ -1262,5 +1287,6 @@ const module = (() => {
uniqueId,
parseGPX,
update_gpx_info,
what3words,
};
})();
7 changes: 7 additions & 0 deletions application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@
remove marker
</div>

<h2>What3words</h2>
<div class="item" id="what3words" tabindex="3"></div>





<h2>Routing</h2>
<div class="item" data-action="set_marker_route_start" tabindex="3">
set as start point
Expand Down

0 comments on commit 6256c71

Please sign in to comment.