flutter_animarker icon indicating copy to clipboard operation
flutter_animarker copied to clipboard

Rotating clockwise >180 degrees when marker can loop over to rotate counter clockwise.

Open efea-umich opened this issue 3 years ago • 5 comments

When a marker's bearing should go over 0 to rotate counter-clockwise (e.g. when going from 5 degrees to 355 degrees when taking a left turn), the marker instead rotates clockwise, spanning 350 degrees when it could have rotated 10 degrees counter clockwise.

The issue only occurs when the marker's bearing must "loop over" the zero mark.

efea-umich avatar Jul 27 '21 11:07 efea-umich

yes exactly, it tries to avoid looping over the 0 mark.

@efea-umich Did you manage to find a workaround to this?

manishrelani avatar Oct 21 '21 10:10 manishrelani

Any update on this?

hasnainusti avatar Dec 09 '21 12:12 hasnainusti

Well, I found a workaround on this.

I just used simple if-else condition

void _locationListener() {
    if (description.latLngListener != null) {
      /// check it first weather rotation is grater than 180 or not
      if ((wrapper.locationTween.begin.bearing -
                  wrapper.locationTween.end.bearing)
              .abs() >
          180) {
        var bearing = wrapper.locationTween.begin.bearing;

        /// calculate total rotation complated
        final complatedRotation = (bearing - _bearingAnimation.value).abs();

        /// cheking for clockwise or anti clockwise
        if (wrapper.locationTween.begin.bearing >
            wrapper.locationTween.end.bearing) {
          // clock wise
          bearing = bearing + complatedRotation;
          if (bearing > 360) bearing = bearing - 360;
          /// as we are not using default animation value so our rotation will complate ealier,
          /// and it will try to go further rotatio.
          /// so we need to keep our bearing between given two points(Start and end points)
          if (bearing > wrapper.locationTween.begin.bearing ||
              bearing < wrapper.locationTween.end.bearing) {
            description
                .latLngListener!(_proxyAnim.value.copyWith(bearing: bearing));
          } else {
            description.latLngListener!(_proxyAnim.value
                .copyWith(bearing: wrapper.locationTween.end.bearing));
          }
        } else {
          /// anti-clock wise
          bearing = bearing - complatedRotation;
          if (bearing < 0) bearing = 360 - bearing.abs();
          if (bearing < wrapper.locationTween.begin.bearing ||
              bearing > wrapper.locationTween.end.bearing) {
            description
                .latLngListener!(_proxyAnim.value.copyWith(bearing: bearing));
          } else {
            description.latLngListener!(_proxyAnim.value
                .copyWith(bearing: wrapper.locationTween.end.bearing));
          }
        }
      } else {
        description.latLngListener!(value);
      }
    }
  }

at this function

manishrelani avatar Dec 09 '21 14:12 manishrelani

Thanks. Any idea how to implement polyline with the marker moving?

hasnainusti avatar Dec 10 '21 05:12 hasnainusti

Thanks @manishrelani

ShubhamDalal avatar Jul 27 '22 04:07 ShubhamDalal