【问题标题】:Android setRotation on marker hiding marker标记隐藏标记上的Android setRotation
【发布时间】:2019-04-05 07:02:23
【问题描述】:

我想根据方向移动和旋转标记,移动标记工作正常,但是当我添加标记旋转时它隐藏标记,当我评论 setRotation() 方法时,我使用以下代码进行标记移动动画和旋转它工作完美但是当我取消注释 setRotation() 行时,它会在位置更新时隐藏标记

public void animateMarker(final LatLng toPosition,final LatLng neLatLong,
                          final boolean hideMarker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 200;

    final Interpolator interpolator = new LinearInterpolator();

    handler.post(new Runnable() {
        @Override
        public void run() {
         long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed
                    / duration);
            curMarker.setPosition(toPosition);
            curMarker.setRotation(getBearing(toPosition,neLatLong));

            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            } else {
                if (hideMarker) {
                    curMarker.setVisible(false);
                } else {
                    curMarker.setVisible(true);
                }
            }
        }
    });
}


private float getBearing(LatLng begin, LatLng end) {
    double lat = Math.abs(begin.latitude - end.latitude);
    double lng = Math.abs(begin.longitude - end.longitude);

    if (begin.latitude < end.latitude && begin.longitude < end.longitude)
        return (float) (Math.toDegrees(Math.atan(lng / lat)));
    else if (begin.latitude >= end.latitude && begin.longitude < end.longitude)
        return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 90);
    else if (begin.latitude >= end.latitude && begin.longitude >= end.longitude)
        return (float) (Math.toDegrees(Math.atan(lng / lat)) + 180);
    else if (begin.latitude < end.latitude && begin.longitude >= end.longitude)
        return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 270);
    return -1;
}

【问题讨论】:

    标签: android google-maps google-maps-markers


    【解决方案1】:

    确保为您的标记设置.anchor(0.5f, 0.5f),并更好地使用来自Google Maps Android API Utility Library SphericalUtil.computeHeading() 而不是您的private float getBearing(LatLng begin, LatLng end)

    【讨论】:

      猜你喜欢
      • 2015-05-26
      • 1970-01-01
      • 2014-12-12
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多