geolocation continuely returning 'POSITION_UNAVAILABLE' in wearable app

我的未来我决定 提交于 2020-06-29 05:57:32

问题


I've been trying to get a simple web app displaying geo coordinates and speed however I am receiving a 'POSITION_UNAVAILABLE' error every time.

I've put the following permissions in the config.xml file;

<feature name="http://tizen.org/feature/feedback.vibration"/>
<feature name="http://tizen.org/feature/location"/>
<tizen:privilege name="http://tizen.org/privilege/location"/>
<tizen:privilege name="http://tizen.org/privilege/power"/>
<tizen:profile name="wearable"/>
<tizen:setting hwkey-event="enable"/>
<tizen:setting background-support="enable"/>

And in the HTML page

<html>
<head>
<meta name="viewport" content="width=device-width,user-scalable=no">
<title>List</title>
<link rel="stylesheet" href="lib/tau/wearable/theme/default/tau.min.css">
<link rel="stylesheet" media="all and (-tizen-geometric-shape: circle)" href="lib/tau/wearable/theme/default/tau.circle.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="ui-page ui-page-active" id="speedPage">
    <header>
        <h2 class="ui-title">Boat speed</h2>
    </header>
    <div class="ui-content">
    <li><p id="speedOutput"></p></li>
    <li><p id="latitude"></p></li>
    <li><p id="longitude"></p></li
    <script>

        var options = {enableHighAccuracy: true, timeout: 50000, maximumAge: 5000};

        function success(position) {
        currentGpsPosLat = position.coords.latitude;
        currentGpsPosLong = position.coords.longitude;
        currentGPSPosLong = position.coords.speed;
        document.getElementById("latitude").innerHTML = currentGpsPosLat;
        document.getElementById("longitude").innerHTML = currentGpsPosLong;         
        }

        function error(error) {
        document.getElementById("speedOutput").innerHTML = error;
        document.getElementById("latitude").innerHTML = error.code;
        }

        navigator.geolocation.getCurrentPosition(success, error, options);


    </script>
    </div>
</div>
<script src="lib/tau/wearable/js/tau.min.js"></script>
<script src="js/circle-helper.js"></script>
<script src="js/app.js"></script>
<script src="js/lowBatteryCheck.js"></script>
</body>


</html>

The output I am getting is

[object PositionError] 2

I've looked up the error code and it is POSITION_UNAVAILABLE. I've also tried

navigator.geolocation.watchPosition(success, error, options);

however I am still getting the same results.

I've verified that the watch is getting location signal by using Here WeGo and a Speedometer app at the same time.

Any help would be greatly appreciated.


回答1:


I am not sure what kind of device do you use, but it seems to me as the issue with privilege restriction existing since Tizen 4.0 - https://developer.tizen.org/development/guides/web-application/security/privacy-related-permissions

'location' is privacy related, so it needs the additional explicit agreement from the user. You can do this using Web API PPM module - https://developer.tizen.org/dev-guide/5.0.0/org.tizen.web.apireference/html/device_api/mobile/tizen/ppm.html

Check current state of user's permission:

> tizen.ppm.checkPermission("http://tizen.org/privilege/location")
< "PPM_ASK"

PPM_ASK says that you properly gave the permission in config.xml, but also need to request it directly from user.

> tizen.ppm.requestPermission("http://tizen.org/privilege/location", (s) => {console.log("success")}, (e) => {console.log("error " + JSON.stringify(e))})

On watch, the pop-up will be shown. User can give the permission then. The result of checking should be as follow:

> tizen.ppm.checkPermission("http://tizen.org/privilege/location")
< "PPM_ALLOW"

Your location-related code should work then (if your device does not have GPS module, you need to pair watch with mobile to have the location properly gathered).



来源:https://stackoverflow.com/questions/57453556/geolocation-continuely-returning-position-unavailable-in-wearable-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!