问题
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