From 3244c7e5e7933383a5ae11ac49d81d3aaf482d76 Mon Sep 17 00:00:00 2001 From: patri <patri@DESKTOP-U7ROG2K.local> Date: Tue, 3 Aug 2021 13:37:10 +0200 Subject: [PATCH] get my position feature --- vcm/index.html | 3 ++- vcm/js/favoriteplaces.js | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/vcm/index.html b/vcm/index.html index ee3e679f3..d58416204 100644 --- a/vcm/index.html +++ b/vcm/index.html @@ -228,7 +228,8 @@ </p><br> <img id="dragFrom" onmouseover="setPointStartEnd('fav')" ondragstart="dragstart_handler(event);" draggable=true src="templates/locationSM.png" style="height:30px;height: 30px; display: inline-block; position: absolute;cursor: -webkit-grab; cursor: grab;"> </div><br><br> - <label class="container contentOne">Andere Lieblingsorte + <button onclick="getLocationFav()">Aktuelle Position</button><br> + <br> <label class="container contentOne">Andere Lieblingsorte <input type="checkbox" id="favcheck" onclick="switchFavPlaces()"> <span class="checkmark"></span> </label> diff --git a/vcm/js/favoriteplaces.js b/vcm/js/favoriteplaces.js index 9fdaa4634..4a5acb8bc 100644 --- a/vcm/js/favoriteplaces.js +++ b/vcm/js/favoriteplaces.js @@ -138,3 +138,49 @@ function switchFavPlaces(){ } } + +// Get Location of User + +function getLocationFav() { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(showPositionFav, showError); + } else { + console.log("Geolocation is not supported by this browser."); + } +} + +function showPositionFav(position) { + console.log("Latitude: " + position.coords.latitude + + " Longitude: " + position.coords.longitude) + var pointd = { + lat:"", + lon:"", + loc:"" + } + pointd.lat = position.coords.latitude + pointd.lon = position.coords.longitude + pointd.loc = "fav" + + setPointFav("fav", pointd); + + var viewpointFavLoc = new vcs.vcm.util.ViewPoint.createViewPointFromExtent([position.coords.longitude - 0.0005, position.coords.latitude - 0.0005, position.coords.longitude + 0.0005, position.coords.latitude + 0.0005]) + viewpointFavLoc.pitch = -40 + vcs.vcm.Framework.getInstance().getActiveMap().gotoViewPoint(viewpointFavLoc); +} + +function showError(error) { + switch(error.code) { + case error.PERMISSION_DENIED: + console.log("User denied the request for Geolocation.") + break; + case error.POSITION_UNAVAILABLE: + console.log("Location information is unavailable.") + break; + case error.TIMEOUT: + console.log("The request to get user location timed out.") + break; + case error.UNKNOWN_ERROR: + console.log("An unknown error occured") + break; + } +} \ No newline at end of file -- GitLab