【问题标题】:Android GPS accuracy only high when Google Maps route guidens is ON?Android GPS 精度只有在 Google Maps 路线引导开启时才高?
【发布时间】:2018-07-17 01:09:51
【问题描述】:

我需要在我的 Android 应用中使用准确的 GPS 位置。我正在使用这个 Cordova 插件来实现 GPS 定位:https://github.com/pmwisdom/cordova-background-geolocation-services

这是请求 GPS 位置的代码:

if (locationClientAPI == null) {
            connectToPlayAPI();
        } else if (locationClientAPI.isConnected()) {
            locationRequest = LocationRequest.create()
                    .setPriority(translateDesiredAccuracy(LocationRequest.PRIORITY_HIGH_ACCURACY))
                    .setFastestInterval(4000)
                    .setInterval(5000)
                    .setSmallestDisplacement(0);

            LocationServices.FusedLocationApi.requestLocationUpdates(locationClientAPI, locationRequest, locationUpdatePI);
            this.isRecording = true;

            if(isDebugging) {
                Log.d(TAG, "- Recorder attached - start recording location updates");
            }
        } else {
            locationClientAPI.connect();
        }

它适用于许多 Android 手机,但在某些(例如三星 Galaxy S8)上,准确性非常差。通常 500-1500m 对应用程序完全不可用。我还观察到,如果我同时打开谷歌地图,位置也到处都是,直到我启动路线指南——然后它几乎立刻就变成了现场。如果我使用我的应用程序,当路线指南打开时,一切都非常准确和漂亮。

在 Android 设置中,我的应用可以使用最高的 GPS 精度。

如何在不启用谷歌地图的路线引导的情况下实现高精度。

【问题讨论】:

  • 您在哪个版本的 Android 上遇到了准确性问题?
  • @DaveAlden Android 7.0

标签: android google-maps cordova gps google-location-services


【解决方案1】:

这个怎么样?

var option = {
  enableHighAccuracy: true // use GPS as much as possible
};
plugin.google.maps.LocationService.getMyLocation(option, function(location) {
    var text = ["Current your location:\n",
      "latitude:" + location.latLng.lat.toFixed(3),
      "longitude:" + location.latLng.lng.toFixed(3),
      "speed:" + location.speed,
      "time:" + location.time,
      "bearing:" + location.bearing].join("\n");

    alert(text);
});

https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.0.0/ReleaseNotes/v2.2.0/README.md#locationservicegetmylocation-without-map

【讨论】:

  • 我们需要使用本地函数来定位位置
  • 这个插件为Android和iOS提供原生功能。
猜你喜欢
  • 2016-02-18
  • 1970-01-01
  • 1970-01-01
  • 2021-10-11
  • 2017-06-23
  • 2016-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多