diff --git a/vcm/index.html b/vcm/index.html index ee3e679f3ad4af209b2ab2f6e484054099e5e3e3..d584162047fc5b6af1973cb81895e684009571d9 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 9fdaa46341172682f15b536e804acdf01904908f..4a5acb8bcbc6f3f2037933a68c5575ab140d4968 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