Getting Speed using Google Play Location API

2019-04-09 12:01发布

问题:

I am using fused location provider from the new GooglePlay API(LocationClient class). But the method Location.GetSpeed() is not returning correct speed (shows 0). I read that I have to use LocationManager class to get the speed, but when I tried LocationManager a new problem occured. The location manager NetworkProvider is not working, here is a thread with the problem http://code.google.com/p/android/issues/detail?id=57707 . So what is the best way to get the speed of movement. I tried calculating it distance/time but it is not accurate..

回答1:

The only sensor that delivers speed is GPS.
Wlan and GSm cell Tower locatining cannot deliver speed.

If you need speed, you have to make sure that GPS is used exlusivley as Location Provider. You cannot use NetworkProvider for that task.

If speed is an important requirement, which has higher priority than battery consumption you have to stay with GPS Provider only. You have to avoid the fused location provider.

Its technically not possible to have speed without GPS.



回答2:

I also encountered this problem when I was using Google Play Location API, I hope this can help.

It returns 0 because your device cannot get a lock on the GPS, or cannot connect to the GPS.

I tried to get the speed using an older lenovo device and it returns 0 because it cannot lock on a gps.

I tried using a samsung galaxy nexus and it returned my speed(has a better GPS sensor).

The GPS sensor in your phone might not be good or you are in an area that has a weak GPS signal such as inside a house or building.

Even if you use the locationManager to get the speed if you are not connected to the gps, your getSpeed will still return 0.