【问题标题】:Google play service sample not getting location offlineGoogle Play 服务示例未离线获取位置
【发布时间】:2018-05-11 17:25:59
【问题描述】:

我正在开发基于位置的应用程序。我正在使用LocationUpdatesForegroundService 示例代码。 哪个是Service 以获取位置详细信息

在某些情况下,位置没有得到。

喜欢。

GPS 和互联网已开启,我正在获取详细位置信息

但是,

GPS 和 Internet 处于离线状态我无法获取位置详细信息。

案例: 启动应用程序我开始为获取位置提供服务,但 gps 关闭案例在我 gps 开启后首先提示请 gps 开启。

但没有得到 LOCATION mFusedLocationClient.getLastLocation 方法 task.getResult()null

请解决我的问题。

谢谢

注意: 此代码适用于 MOTO E os 版本 4.4.4。 但不能在 LAVA a97 os 6.0 版中运行

我正在使用这个示例:- https://github.com/googlesamples/android-play-location/tree/master/LocationUpdatesForegroundService

【问题讨论】:

  • 得到了同样的...遵循所有的教程,但总是得到空

标签: android gps location google-play-services android-fusedlocation


【解决方案1】:

您只能通过在textview 中获取LocationUpdates 来获取详细信息,地图不会在offline 中为您提供更新。如果您使用 textview 获取更新,您可能会忘记这一点。

在 Manifest.xml 中添加 CourseLocation 权限

【讨论】:

  • 你的意思是
  • 好的。但是你为什么要开始服务,我不知道你为什么要这样做。我认为获取位置详细信息不需要服务
  • 我需要准确的 GPS。这就是我关注谷歌官方样本的原因。如果您有另一个让 gps 离线的好例子,请告诉我
  • 我能给出另一个与你不同的答案吗?你不需要我的代码中的服务,但它会给你准确的结果
  • 我不确定它会不会。我很久以前就编码了这个。如果你需要我可以给你
【解决方案2】:

onCreate()

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
  // Called when a new location is found by the network location provider.
  makeUseOfNewLocation(location);
}

public void onStatusChanged(String provider, int status, Bundle extras) {}

public void onProviderEnabled(String provider) {}

public void onProviderDisabled(String provider) {}
  };
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

最后不要忘记在清单中添加权限并在 Java 代码中处理权限,因为dynamic permissions

就是这样。

我希望即使离线也能正常工作。

【讨论】:

  • 对你有用吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-30
  • 2017-08-03
  • 2019-03-20
  • 2017-10-25
  • 2018-10-09
  • 2014-08-31
  • 2018-04-04
相关资源
最近更新 更多