Skip to content

Commit

Permalink
what3words
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Jun 19, 2024
1 parent 0d7de1b commit 40b3668
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 66 deletions.
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 "sorry, could not be determined";
});
};

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
2 changes: 1 addition & 1 deletion application/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.9.791",
"version": "1.9.792",
"version_name": "hotline",
"name": "o.map",
"description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.",
Expand Down
2 changes: 1 addition & 1 deletion application/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],

"b2g_features": {
"version": "2.0.95",
"version": "2.0.96",
"id": "o.map",
"core": true,
"categories": ["utilities"],
Expand Down
28 changes: 27 additions & 1 deletion docs/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 "sorry, could not be determined";
});
};

return {
hotline,
convert_units,
Expand All @@ -1262,5 +1287,6 @@ const module = (() => {
uniqueId,
parseGPX,
update_gpx_info,
what3words,
};
})();
1 change: 1 addition & 0 deletions docs/assets/js/openweather.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const weather = (() => {
//todo > 2024 06 change to 3.O
let openweather_call = function (lat, lng, apikey, callback) {
let xhr = new XMLHttpRequest({
mozSystem: true,
Expand Down
13 changes: 2 additions & 11 deletions docs/assets/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const settings = ((_) => {
let save_settings = function () {
localStorage.setItem("owm-key", document.getElementById("owm-key").value);
localStorage.setItem(
"ipbase-key",
document.getElementById("ipbase-key").value
);

localStorage.setItem(
"routing_profil",
Expand Down Expand Up @@ -78,9 +74,7 @@ const settings = ((_) => {
localStorage["tracking-notification-time"] || 0,

openweather_api: localStorage.getItem("owm-key"),
ipbase_api: localStorage.getItem("ipbase-key")
? localStorage.getItem("ipbase-key")
: "",

ors_api: localStorage.getItem("ors-key"),
routing_profil: localStorage.getItem("routing_profil")
? localStorage.getItem("routing_profil")
Expand Down Expand Up @@ -176,7 +170,6 @@ const settings = ((_) => {
//set values in setting page

document.getElementById("owm-key").value = setting.openweather_api;
document.getElementById("ipbase-key").value = setting.ipbase_api;
document.getElementById("ors-key").value = setting.ors_api;
document.getElementById("routing-profil").value = setting.routing_profil;

Expand Down Expand Up @@ -244,7 +237,6 @@ const settings = ((_) => {

setTimeout(() => {
document.getElementById("owm-key").value = setting.openweather_api;
document.getElementById("ipbase-key").value = setting.ipbase_api;
document.getElementById("ors-key").value = setting.ors_api;
document.getElementById("routing-profil").value =
setting.routing_profil;
Expand Down Expand Up @@ -293,8 +285,7 @@ const settings = ((_) => {
setTimeout(() => {
document.getElementById("owm-key").value =
setting.openweather_api;
document.getElementById("ipbase-key").value =
setting.ipbase_api;

document.getElementById("ors-key").value =
setting.ors_api;
document.getElementById("routing-profil").value =
Expand Down
13 changes: 7 additions & 6 deletions docs/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 Expand Up @@ -240,12 +247,6 @@ <h2>Routing Service</h2>
<div class="toogle-button"></div>
</div>

<h2>IP Geolocation</h2>
<div class="item input-parent" tabindex="0">
<label for="ipbase-key">ipbase.com API-Key</label>
<input type="text" class="qr" id="ipbase-key" />
</div>

<h2>Crosshair</h2>
<div class="item input-parent flex" tabindex="3">
<label for="crosshair-ckb" class="grid-col-14"
Expand Down
57 changes: 14 additions & 43 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,20 +346,6 @@ document.addEventListener("DOMContentLoaded", function () {
helper.getManifest(manifest);
}

let geoip_callback = function (data) {
helper.side_toaster(
"your position was found out via your ip address, the accuracy is rather poor",
2000
);
mainmarker.current_lat = data[0];
mainmarker.current_lng = data[1];
mainmarker.device_lat = data[0];
mainmarker.device_lng = data[1];
myMarker.setLatLng([mainmarker.device_lat, mainmarker.device_lng]).update();
setTimeout(function () {
map.setView([mainmarker.device_lat, mainmarker.device_lng], 12);
}, 1000);
};
//build menu
let build_menu = function () {
let el = document.querySelector("div#maps");
Expand Down Expand Up @@ -456,8 +442,6 @@ document.addEventListener("DOMContentLoaded", function () {

files = uniqueData;

console.log(files);

uniqueData.forEach((e) => {
if (e.type == "gpx") {
document.getElementById("gpx-title").style.display = "block";
Expand Down Expand Up @@ -991,33 +975,20 @@ document.addEventListener("DOMContentLoaded", function () {
}

function error(err) {
if (setting.ipbase_api != "") {
var z = confirm(
"do you want to find out your position by your ip address ?"
);
}

if (z == true) {
helper.geoip(geoip_callback, setting.ipbase_api);
} else {
helper.side_toaster(
"Position not found, load last known position",
4000
);
mainmarker.current_lat = mainmarker.last_location[0];
mainmarker.current_lng = mainmarker.last_location[1];
mainmarker.current_alt = 0;

mainmarker.device_lat = mainmarker.last_location[0];
mainmarker.device_lng = mainmarker.last_location[1];
geolocationWatch();
myMarker
.setLatLng([mainmarker.device_lat, mainmarker.device_lng])
.update();
setTimeout(function () {
map.setView([mainmarker.device_lat, mainmarker.device_lng], 12);
}, 1000);
}
helper.side_toaster("Position not found, load last known position", 4000);
mainmarker.current_lat = mainmarker.last_location[0];
mainmarker.current_lng = mainmarker.last_location[1];
mainmarker.current_alt = 0;

mainmarker.device_lat = mainmarker.last_location[0];
mainmarker.device_lng = mainmarker.last_location[1];
geolocationWatch();
myMarker
.setLatLng([mainmarker.device_lat, mainmarker.device_lng])
.update();
setTimeout(function () {
map.setView([mainmarker.device_lat, mainmarker.device_lng], 12);
}, 1000);
}

navigator.geolocation.getCurrentPosition(success, error, options);
Expand Down
2 changes: 1 addition & 1 deletion docs/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.9.791",
"version": "1.9.792",
"version_name": "hotline",
"name": "o.map",
"description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.",
Expand Down
2 changes: 1 addition & 1 deletion docs/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],

"b2g_features": {
"version": "2.0.95",
"version": "2.0.96",
"id": "o.map",
"core": true,
"categories": ["utilities"],
Expand Down

0 comments on commit 40b3668

Please sign in to comment.