简体   繁体   English

如何使用位置服务关闭当前位置

[英]how to get current location using location services turned off

I use the following code to get Current Location from a Network provider turn off in my application: 我使用以下代码从应用程序中关闭网络提供商的“当前位置”:

LocationManager mgr = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean network_enabled = mgr.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(network_enabled){
Location location = mgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

This is expected from a Network provider. 可以从网络提供商处获得。 But the problem is: when location services turn on its return true and finally get current location. 但是问题是:当定位服务开启时,返回true并最终获得当前位置。 Suppose I turn off return false and get values 0.0,0.0. 假设我关闭return false并获得值0.0,0.0。

If any other way to get current location using network provider when location service turn off? 定位服务关闭时,是否还有其他方法可以使用网络提供商获取当前位置?

Use Fused Location API of Google. 使用Google的融合位置API。

https://developers.google.com/location-context/fused-location-provider/ https://developers.google.com/location-context/fused-location-provider/

It is more convenient. 比较方便。 It provide last known location. 它提供了最后的已知位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使在用户强行关闭gps的情况下,如何使用fusionloaction api在后台获取位置信息? - How to get location information in background using fusedloaction api even when gps is turned off forcefully by the user? 如何获得当前位置? - How to get current location? (Android)如何使用Google Play服务检索当前位置 - (Android) How to retrieve current location using Google Play Services 如何使用 FusedLocationProviderClient 在 GoogleMap 中获取当前位置 - How to get current Location in GoogleMap using FusedLocationProviderClient 如何获得当前位置和下一个当前位置之间的距离 - How to get distance between current location and the next current location 在关闭GPS的情况下打开应用时无法获取GPS当前位置 - Can not get GPS current location when open the app with off GPS 如何从Android中打开或关闭位置获取响应? - how to get the response from location on or off in android? 如何使用OverlayItem获取用户的当前位置并将其绘制在地图上 - How to get user's current location and plot it on the map using OverlayItem 如何使用ZK框架动态获取当前位置? - How to get the current location dynamically using ZK framework? Android:如何使用 GPS 提供商获取离线当前位置? - Android: How to get offline current location using GPS provider?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM