Retrieve the Last Known Location when the smartphone was turned off a long time

五迷三道 提交于 2020-01-03 05:15:39

问题


I'm working on an Android project and the application needs the GPS coordinates to work.

So after a long sleep, the line of code below give me null when I try to get the coordinates

locationManager = (LocationManager)getApplicationContext().getSystemService(LOCATION_SERVICE);
Location _lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

So to get them, I've to start Google Maps which is a little bit disapointing . I already read a lot of threads but anyone really helpful. I'm using a Samsung S2 and a S3 but I also read that the cause is a bug in the native service which stuck in a loop trying to restart itslef.

Is anybody know how can I figure this out?


回答1:


For Geolocation of your device, you can use many providers, such as LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER and LocationManager.PASSIVE_PROVIDER.

You will find more infos in Location Strategies guideline



来源:https://stackoverflow.com/questions/20067751/retrieve-the-last-known-location-when-the-smartphone-was-turned-off-a-long-time

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