Geolocation 无法获取Nexus 4和10上的准确地理位置
如何在android设备上获得最准确的地理位置,我尝试了以下代码片段,但在Nexus 4和10上,即使打开gps,它也无法工作:Geolocation 无法获取Nexus 4和10上的准确地理位置,geolocation,gps,wifi,geocoding,locationmanager,Geolocation,Gps,Wifi,Geocoding,Locationmanager,如何在android设备上获得最准确的地理位置,我尝试了以下代码片段,但在Nexus 4和10上,即使打开gps,它也无法工作: LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); String locationProvider = locationManager.getBestProvider(new Criteri
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);
}
}
通过将
LocationProvider
显式设置为GPS提供程序,可以获得最精确的位置。预计精度通常为3-6米,在城市峡谷中可达30米。您需要在室外自由观看天空。
外出后,第一个有效位置预计会延迟20-40秒。这是什么意思,它不起作用?