我正在制作Android应用,需要使用GPS来记录司机统计数据,例如速度,航向,海拔高度和长/纬度,并具有良好的准确性。
我需要每秒跟踪一下这个位置,但我似乎没有得到准确的结果。我在市场上尝试过一款Android GPS应用程序,可以返回正确的结果。
到目前为止,我有这个。
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
VehicleListener vl = new VehicleListener();
locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, vl);
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
lat =location.getLatitude();
lon = location.getLongitude();
}
答案 0 :(得分:2)
您使用的是空标准。如果您想要更准确,请尝试使用:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
VehicleListener vl = new VehicleListener();
locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, vl);
if (location != null) {
System.out.println("Provider " + provider + " has been selected.");
lat =location.getLatitude();
lon = location.getLongitude();
}