地理定位在可穿戴应用程序中继续返回“POSITION_UNAVAILABLE" [英] geolocation continuely returning 'POSITION_UNAVAILABLE' in wearable app
问题描述
我一直在尝试获得一个显示地理坐标和速度的简单网络应用,但是我每次都收到POSITION_UNAVAILABLE"错误.
我已经在 config.xml 文件中添加了以下权限;
<功能名称="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"/>
在 HTML 页面中
<头><meta name="viewport" content="width=device-width,user-scalable=no"><title>列表</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">头部><身体><div class="ui-page ui-page-active" id="speedPage"><标题><h2 class="ui-title">船速</h2></标题><div class="ui-content"><li><p id="speedOutput"></p></li><li><p id="纬度"></p></li><li><p id="经度"></p></li<脚本>var options = {enableHighAccuracy: true, timeout: 50000, maximumAge: 5000};功能成功(位置){currentGpsPosLat = position.coords.latitude;currentGpsPosLong = position.coords.longitude;currentGPSPosLong = position.coords.speed;document.getElementById("latitude").innerHTML = currentGpsPosLat;document.getElementById("longitude").innerHTML = currentGpsPosLong;}函数错误(错误){document.getElementById("speedOutput").innerHTML = 错误;document.getElementById("latitude").innerHTML = error.code;}navigator.geolocation.getCurrentPosition(成功,错误,选项);
<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></html>
我得到的输出是
[对象位置错误]2
我查看了错误代码,它是 POSITION_UNAVAILABLE.我也试过
navigator.geolocation.watchPosition(success, error, options);
但是我仍然得到相同的结果.
我已通过同时使用 Here WeGo 和 Speedometer 应用验证手表正在获取位置信号.
任何帮助将不胜感激.
我不确定您使用的是哪种设备,但在我看来,这是自 Tizen 4.0 以来存在的权限限制问题 - https://developer.tizen.org/development/guides/web-application/security/privacy-related-permissions
'location' 与隐私相关,因此需要用户的额外明确同意.您可以使用 Web API PPM 模块执行此操作 - https://developer.tizen.org/dev-guide/5.0.0/org.tizen.web.apireference/html/device_api/mobile/tizen/ppm.html
检查用户权限的当前状态:
<代码>>tizen.ppm.checkPermission("http://tizen.org/privilege/location")<PPM_ASK"
PPM_ASK 表示您在 config.xml 中正确授予了权限,但还需要直接向用户请求.
<代码>>tizen.ppm.requestPermission("http://tizen.org/privilege/location", (s) => {console.log("success")}, (e) => {console.log("error" + JSON.stringify(e))})
在观看时,将显示弹出窗口.然后用户可以授予权限.检查结果如下:
<代码>>tizen.ppm.checkPermission("http://tizen.org/privilege/location")<PPM_ALLOW"
您的位置相关代码应该可以工作(如果您的设备没有 GPS 模块,您需要将手表与手机配对才能正确收集位置).
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.
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).
这篇关于地理定位在可穿戴应用程序中继续返回“POSITION_UNAVAILABLE"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!