mobile - 从移动浏览器获取 GPS 数据是否已知有些不稳定?
问题描述
我目前有工作代码,当用户按下按钮分享他们的位置时,浏览器会弹出“你想分享你的位置吗?” 然后前端代码处理结果。(HTML5 地理定位 API)
我注意到失败率约为 10%,我的意思是position_unavailable
触发率或以下代码中的未知错误:
$("#share-location-btn").click(shareLocation);
function shareLocation() {
$("#share-location-btn").prop("disabled", true);
$("#checking-location-msg").removeClass("hidden");
navigator.geolocation.getCurrentPosition(validateLocation, handleGeolocationError);
}
function handleGeolocationError(error) {
let errorText;
switch(error.code) {
case error.PERMISSION_DENIED:
errorText = "Location sharing was denied";
break;
case error.POSITION_UNAVAILABLE:
errorText = "Location can't be determined - contact us at XXX-XXX-XXXX";
break;
default:
errorText = "Unknown error - contact us at XXX-XXX-XXXX";
break;
}
errorUIHelper(errorText);
}
我正在尝试进一步降低失败率。我觉得这一定是可能的,因为像自行车共享应用程序(例如 Lime)这样的服务实际上需要 GPS 来执行每个解锁操作,并且考虑到当这不起作用时他们没有按需客户服务,我' m 假设他们已经实现了超低的故障率。
但是,这些服务当然是应用程序。我知道应用程序通常为地理围栏服务提供了更大的灵活性(例如,即使手机被锁定,也可以持续发送位置信息,而不需要用户交互)。
也就是说,我有点想确认,在移动浏览器而不是应用程序上进行地理围栏更有经验的人......移动浏览器是否只是已知的不稳定?因为移动设备、操作系统、浏览器等有很多可能的排列?
如果这导致迁移到应用程序,那么应用程序在这方面是否也通常不那么不稳定?
解决方案
推荐阅读
- regex - 使用正则表达式匹配使用 netstat -nb python 的进程名称
- .net-core - VSTS - dotnet restore - PackageCache 不存在
- bash - 将 API 转换为 HTTPS 后 pwd 命令返回“/”
- swift3 - 简单的活动跟踪器 Swift 代码
- javascript - 使用 for 循环反转数组
- wordpress - 如何在 docker-compose.yml 中运行 wp cli
- android - 获取已安装应用程序的列表,不包括内置应用程序
- android - 通话结束后获取来电者电话号码然后开始活动
- php - 在 AJAX 发送的 PHP 文件中重用数据库连接 (PDO)
- graph-theory - 如何计算具有 5 个顶点的图形的直径?