java - Android 应用位置与速度

标签 java android gps location

我正在制作一个 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();
    }

最佳答案

您使用的是空条件。如果你想要更准确的尝试这个:

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();
}

关于java - Android 应用位置与速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8016757/

相关文章:

Android Python 获取gps状态

javafx TextArea 抛出 NullPointerException

java - 具有公共(public)字符串数组的静态内容的非静态字段

java - 垫 : How do you diagnose "x instances of "byte[ ]", loaded by "<system class loader >"occupy y (z%) bytes" memory issues?

java - 如何获取当前时间附近的时间 [Android Studio]

python - 使用 basemap 绘制芝加哥周围的 GPS 坐标

java - 在 Android 布局 XML 中将 TextView 放置在 EditText 元素之前会导致 EditText 不显示

java - 从文件中读取属性并在ant中分配给不同的名称?

android - 如何正确使用Eclipse的Drawable文件夹?

database - 为运输地点制作数据模型