gauris26 / flutter_animarker

Sometimes you need more than place a marker in the maps, you required a smoothly through Google Maps canvas.
https://gaurisjavier.com/
BSD 3-Clause "New" or "Revised" License
58 stars 51 forks source link

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

Open efea-umich opened 3 years ago

efea-umich commented 3 years ago

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.

manishrelani commented 3 years ago

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

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

hasnainusti commented 2 years ago

Any update on this?

manishrelani commented 2 years ago

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

hasnainusti commented 2 years ago

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

ShubhamDalal commented 2 years ago

Thanks @manishrelani