简体   繁体   中英

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. Suppose I turn off return false and get values 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.

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

It is more convenient. It provide last known location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM