android - locationManager.getLastKnownLocation() 返回 null

标签 android geolocation location latitude-longitude

我不明白为什么 locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 返回位置 null。我给予了所有许可,但它的 reutning 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();
                    }
                }
            }
        }

最佳答案

我遇到了同样的问题。这是因为我的设备没有存储最后一个已知位置。我只是去谷歌地图并用 GPS 精确定位我的位置,然后为 getLastKnownLocation() 返回一个值

关于android - locationManager.getLastKnownLocation() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23906926/

相关文章:

java - 如何在 SharedPreferences 中保存和检索日期

android - 为什么 Android Emulator 显示黑屏,Android 闪烁?

php - 如何在行和列反转时显示数据库中的数据

javascript - 允许用户在网站中输入他的位置(地址)

api - Flickr API - 通过标签、文本或位置获取最佳照片

android - 浏览 Android SQLite 数据库中的数据

MySQL 5.7 地理空间索引,将点集中在一个点导致性能问题

laravel - 将坐标保存到数据库,然后进行范围搜索

iphone - 如何从装有 iOS 5 的新 iPhone 获取历史位置数据(供个人使用)?

android - Ant 脚本中 aapt 元素的文档