getLastKnownLocation() always return the same location

偶尔善良 提交于 2019-12-03 12:52:48

There is a bug with LocationProvider on some platforms like Samsung, custom Android build. You need to call this code (which actually does nothing), which triggers the phone's background cache to update its current location.

If you dont believe me, change your Gps position to a different location about 200m away, load your app, you dont notice the location gps change. Now, just load Maps app on your phone and suddenly your app will show current location.

To do this trigger programmatically put these lines just before your getLastKnownLocation call.

HomeScreen.getLocationManager().requestLocationUpdates(
    LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
        @Override
        public void onProviderEnabled(String provider) {
        }
        @Override
        public void onProviderDisabled(String provider) {
        }
        @Override
        public void onLocationChanged(final Location location) {
        }
    });

Edit

OR

Use the new api's LocationClient instead of LocationProvider.

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