无法在Nexus 4和10上获得准确的地理位置

时间:2014-02-13 13:45:55

标签: geolocation gps wifi geocoding locationmanager

如何在Android设备上获得最准确的地理位置,我尝试使用以下代码片段但是在Nexus 4和10上,即使打开gps后它也无法正常工作:

LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
            String locationProvider = locationManager.getBestProvider(new Criteria(), true);
            if (locationProvider != null) {
                //Log.d(TAG, "locationProvider is not null");
                Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);

                if (lastKnownLocation != null) {
                    AppConstants.lat = latLon[0] = lastKnownLocation.getLatitude();
                    AppConstants.lon = latLon[1] = lastKnownLocation.getLongitude();
                    retryGenerating = false;
                    //Log.d(TAG, "lastKnownLocation, lat = " + AppConstants.lat + ", lon = " + AppConstants.lon);

                }
}

1 个答案:

答案 0 :(得分:0)

通过明确将LocationProvider设置为GPS提供商,您获得的最准确位置。在城市峡谷中,精度通常为3-6米,高达30米。

你需要在外面,对天空有自由的看法 出门后,第一个有效位置的延迟时间为20-40秒。