Getting my gps location while I'm offline

喜欢而已 提交于 2020-01-06 08:22:54

问题


I've doing some research about getting my gps position. I'm using google maps API v2 so in order to get my current position I used this

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    List<String> providers = locationManager.getAllProviders();
    Criteria criteria = new Criteria();
    bestProvider = locationManager.getBestProvider(criteria, false);

    Location location = locationManager.getLastKnownLocation(bestProvider);

so from my understanding there is a list in the locationManager and getLastKnowLocation() returns the last entry from that list. Also if this list is not empty I can get the last entry while my application is offline.

I happened to have my wifi off for the weekend and checked to see if it works but no location was returned to me.

So my first question is: how long are the entries in the list available for my application to retrieve them provided there is no internet connection for a while.

Also the location that I will be retrieving will be the last which was fixed while I was online correct? so even If I can retrieve it, it won't be accurate so is there another way to get my current gps location while my cell is offline? (ie via gps or gsm network) Thank you for your time.


回答1:


Firstly, you don't have to be connected to internet to get location updates through GPS. If your device supports GPS, it will get connected to the GPS satellites if your outdoors and you can get the location updates through GPS. Read this to know how to use location providers.

Also be informed that if the provider is not turned on, getLastKnownLocation() will always return null. Quoting from android documentaion,

If the provider is currently disabled, null is returned.



来源:https://stackoverflow.com/questions/21380188/getting-my-gps-location-while-im-offline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!