如何用轴承机器人平稳地旋转地图视图 [英] How to rotate map view smoothly with bearing in android

查看:215
本文介绍了如何用轴承机器人平稳地旋转地图视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当用户更改自己的方向,即如果用户需要左,右转动它应该轮换accordingly.I正在旋转地图视图立足当前位置轴承是否正常旋转旋转地图视图,但它是jittering.Here是这是我用旋转code

I am trying to rotate map view when the user changes his direction ie if user takes left and right turns it should rotate accordingly.I am rotating map view basing on current location bearing it is rotating correctly but it was jittering.Here is the code which i used for rotation

   public void onGPSUpdate(Location location) 
{
     boolean check=isBetterLocation(location, tempLoc);
    tempLoc=location;

     if(check){
        showLocation(location);

     }

}
isBetterLocation method is copied from google docs for better location.

private void showLocation(Location loc){
   mRotateView.rotate(-loc.getBearing());             
   }

我注册的时间间隔0和10频繁updates.Here分钟距离的位置更新我的问题是地图视图总是抖动,任何一个可以告诉我,我怎么能平稳地旋转地图视图像其他应用程序,如Waze的地图做.Thanks ...

I registered a location updates with time interval 0 and min distance of 10 for frequent updates.Here my problem is map view is jittering always,can any one tell me how can I smoothly rotate map view like other applications like waze maps do.Thanks...

推荐答案

由于位置的方位值不是非常精确的,往往跳了一下,你应该使用过滤器的轴承。例如,保持最后5轴承值在一个阵列,并使用这些值的平均值作为轴承旋转地图到。或者使用过滤器在解释 SensorEvent文档 - 它更容易使用,可以调整好。

As the bearing values of the Location are not very exact and tend to jump a little, you should use a filter for the bearing. For example, keep the last 5 bearing-values in an array and use the average of those values as the bearing to rotate the map to. Or use the filter explained in the SensorEvent docs - it's easier to use and can be tweaked better.

这将理顺了地图RESP的旋转。保持更稳定。

This will smoothen out the rotation of the map resp. keep it more stable.

编辑:

A版低通滤波器的:

public static float exponentialSmoothing(float input, float output, float alpha) {
    output = output + alpha * (input - output);
    return output;
}

使用它像这样:

use it like so:

final static float ALPHA = 0.33; // values between 0 and 1
float bearing;

// on location/bearing changed:

bearing = exponentialSmoothing(bearing, newBearing, ALPHA);

轴承将要使用的值实际旋转地图, newBearing 将是承载你得到每一个事件,并与 ALPHA 您可以控制​​如何快速或缓慢旋转的作用是一个新的方向,通过加权多少旧的和新的轴承是考虑到了结果。小值重旧值越高,高值晕死了新的价值更高。

bearing would be the value to use to actually rotate the map, newBearing would be the bearing you get from every event, and with ALPHA you can control how quickly or slowly the rotation acts to a new orientation by weighting how much of the old and the new bearing is taken into account for the result. A small value weighs the old value higher, a high value weighs the new value higher.

我希望作品出来更好。

I hope that works out better.

这篇关于如何用轴承机器人平稳地旋转地图视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆