如何使用位置或加速计或其他方式获得的速度在Android应用程序如何使用、应用程序、速度、位置

由网友(泛白的記憶使涐沈迷つ。)分享简介:我工作的应用程序,并得到了速度和距离用户行进。我已经使用了谷歌播放服务位置类来获取速度,但它总是返回我0.0的值,而不是在所有的可靠。我婉精确的速度和距离的实时行驶。I am working on app and try to get the speed and distance travelled by the u...

我工作的应用程序,并得到了速度和距离用户行进。我已经使用了谷歌播放服务位置类来获取速度,但它总是返回我0.0的值,而不是在所有的可靠。我婉精确的速度和距离的实时行驶。

I am working on app and try to get the speed and distance travelled by the user. I have used Google Play services location class to get the speed but it always returns me 0.0 value and not at all reliable. I wan accurate speed and distance travelled at real time.

我有我的设备和安装GPS测速仪应用程序,它的如此完美,即使我走,然后它给了我的速度。我想同样的事情。我很困惑中如何获得速度,使用位置或使用加速度计或有任何其他方式做到这一点?

I have installed GPS Speedometer app on my device and its so perfect that even if i am walking then it gives me the speed. I want to get the same thing. I am confused in how to get speed, using location or using accelerometer or is there any other way to do it?

我的code是这个链接可供选择: -

My code is available on this link :-

Drawing用谷歌地图Android的API V2 在谷歌地图的路径

我发展纯基于位置的应用程序,其中包括地图,速度快,这都与位置相关的事情。

I am developing pure location based app which includes map, speed and other related things which are related to Locations.

如果任何人有任何想法,请您帮我解决速度和距离的问题。

If anyone has any idea please kindly help me on resolving the issue of Speed and Distance.

推荐答案

我不得不面对同样的问题,你可以做的是使用的位选择战略 code。

I had to deal with same problem, what you can do is to use Location Strategies code.

然后,在位置的每次更新,你保存当前更新的时间。所以,你将有更新的previous和当前的位置和时间。

Then, on each update of location, you save the time of the current update. So, you will have the previous and current location, and time of update.

然后你算算这两个位置(旧的和新的)

Then you calculate the distance in meters between those two locations (the old and new one)

private static long calculateDistance(double lat1, double lng1, double lat2, double lng2) {
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2)
            * Math.sin(dLon / 2);
    double c = 2 * Math.asin(Math.sqrt(a));
    long distanceInMeters = Math.round(6371000 * c);
    return distanceInMeters;
}

所以,那么你的距离和时间差,我想会不会是一个大问题,以获得速度。

So, then you have the distance and the time difference, I think it wouldn't be a big deal to get the speed.

阅读全文

相关推荐

最新文章