确定车辆的使用Android的GPS速度车辆、速度、Android、GPS

2023-09-05 08:43:31 作者:﹏从此゛各自安好つ

我想知道如何让使用手机一个车辆的速度,而在使用GPS车辆就位。我已阅读,加速度计不是很准确。另一件事是,将GPS可以访问,而在车辆就位。会不会也有同样的效果,而你是在一个建筑?

下面是一些code我都试过,但我已经使用了网络提供商instead.I将AP preciate的帮助。谢谢...

 包com.example.speedtest;

进口android.app.Activity;
进口android.content.Context;
进口android.location.Location;
进口android.location.LocationListener;
进口android.location.LocationManager;
进口android.os.Bundle;
进口android.widget.Toast;

公共类MainActivity延伸活动{
    LocationManager locManager;
    LocationListener的李;
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        locManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
        LI =新速度();
        locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,LI);
    }
    级的速度实现LocationListener的{
        @覆盖
        公共无效onLocationChanged(位置LOC){
            浮法thespeed = loc.getSpeed​​();
            Toast.makeText(MainActivity.this,将String.valueOf(thespeed),Toast.LENGTH_LONG).show();
        }
        @覆盖
        公共无效onProviderDisabled(字符串为arg0){}
        @覆盖
        公共无效onProviderEnabled(字符串为arg0){}
        @覆盖
        公共无效onStatusChanged(字符串为arg0,INT ARG1,捆绑ARG2){}

    }
}
 

解决方案

GPS工作正常车辆。该 NETWORK_PROVIDER 设置可能不够准确获得可靠的速度,从位置 NETWORK_PROVIDER 甚至可能不包含的速度移动。您可以检查与 location.hasSpeed​​() location.getSpeed​​()将始终返回0)。

怎样提高Android手机的运行速度

如果你发现 location.getSpeed​​()不够准确,或者是不稳定(即波动剧烈),那么你可以自己计算速度取平均值几个GPS位置和除以时间之间距离已过。

I would like to know how to get the speed of a vehicle using your phone while seated in the vehicle using gps. I have read that the accelerometer is not very accurate. Another thing is; will GPS be accessible while seated in a vehicle. Won't it have the same effect as while you are in a building?

Here is some code I have tried but I have used the NETWORK PROVIDER instead.I will appreciate the help. Thanks...

package com.example.speedtest;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity {
    LocationManager locManager;
    LocationListener li;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        locManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
        li=new speed();
        locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, li);
    }
    class speed implements LocationListener{
        @Override
        public void onLocationChanged(Location loc) {
            Float thespeed=loc.getSpeed();
            Toast.makeText(MainActivity.this,String.valueOf(thespeed), Toast.LENGTH_LONG).show();
        }
        @Override
        public void onProviderDisabled(String arg0) {}
        @Override
        public void onProviderEnabled(String arg0) {}
        @Override
        public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}

    }
}

解决方案

GPS works fine in a vehicle. The NETWORK_PROVIDER setting might not be accurate enough to get a reliable speed, and the locations from the NETWORK_PROVIDER may not even contain a speed. You can check that with location.hasSpeed() (location.getSpeed() will always return 0).

If you find that location.getSpeed() isn't accurate enough, or it is unstable (i.e. fluctuates drastically) then you can calculate speed yourself by taking the average distance between a few GPS locations and divide by the time elapsed.