小编use*_*590的帖子

locationManager.getLastKnownLocation()返回null

我不明白为什么 locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);返回位置null.我给了所有的许可,但它的悔改null.

          if (isGPSEnabled) {
            if (location == null) {
                locationManager.requestLocationUpdates(
                        LocationManager.GPS_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("GPS", "GPS Enabled");
                if (locationManager != null) {
                    location = locationManager
                            .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    if (location != null) {
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

android location geolocation latitude-longitude

15
推荐指数
2
解决办法
3万
查看次数