首页 > 解决方案 > 从移动浏览器获取 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 假设他们已经实现了超低的故障率。

但是,这些服务当然是应用程序。我知道应用程序通常为地理围栏服务提供了更大的灵活性(例如,即使手机被锁定,也可以持续发送位置信息,而不需要用户交互)。

也就是说,我有点想确认,在移动浏览器而不是应用程序上进行地理围栏更有经验的人......移动浏览器是否只是已知的不稳定?因为移动设备、操作系统、浏览器等有很多可能的排列?

如果这导致迁移到应用程序,那么应用程序在这方面是否也通常不那么不稳定?

标签: mobilegeolocationlocationmobile-safarigeo

解决方案


推荐阅读