【问题标题】:Is there a way to animate Xamarin.Forms.Maps pin movement有没有办法为 Xamarin.Forms.Maps 引脚移动设置动画
【发布时间】:2018-04-08 22:48:16
【问题描述】:

我只是想知道 xamarin 中是否有一种方法可以转换更改地图针位置并可能旋转自定义地图针以匹配移动方向。我想避免自定义渲染器IF,但我愿意接受这个想法。

非常感谢任何帮助

【问题讨论】:

    标签: c# android ios xamarin.forms maps


    【解决方案1】:

    我建议你使用Xamarin.Forms.GoogleMaps

    关于职位

    您可以先清除,然后在地图上重新添加以刷新位置

    请参阅here

    关于方向

    你可以使用BEARING来达到效果。

    请参阅here

    【讨论】:

    • 您好,感谢您的回答 xamarin forms maps 与 xamarin forms google maps 有何不同?我在折线方面取得了一些进展,想知道我需要重复多少工作
    • 我开始阅读它,用这个控件重做我的项目似乎并没有太多工作,我猜我可能需要更改我的自定义地图。
    • @Kaizer69 您好,您遇到了什么问题?
    • 嗨 Cole,我最初将此标记为答案,因为它使用 googlemaps 包而不是地图解决了很多问题,但我在他们的文档中看不到任何关于翻译、动画从一个位置移动到另一个,地图别针,这是我问题的第一部分。我已经能够改变位置了,但引脚只是神奇地移动而不是平滑过渡。
    【解决方案2】:

    您可以使用自定义动画为 Xamrin Forms Map 上的图钉移动设置动画,如下所示:

        var animation = new Animation(a => pin.Position = new Position(pin.Position.Latitude + 0.0001, pin.Position.Longitude), 1, 2);
        animation.Commit(this, "PinAnimation", 100, 10000, Easing.SinInOut , null, () => false);
    

    docs.microsoft.com 上有关 Xamarin 自定义动画的更多详细信息

    希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      @Andy Sinclair 的回答是一个很好的起点(the docs 也是如此),但如果您想为地图图钉设置动画(带有纬度、经度和可能的方位),您需要分别为每个标量值设置动画,就像这样:

      var position = yourTargetPinPosition;
      new Animation {
          // Animate the change in latitude
          { 0, 1, new Animation(lat => pin.Position = new Position(lat, pin.Position.Longitude), pin.Position.Latitude, position.Latitude) },
          // Animate the change in longitude
          { 0, 1, new Animation(lng => pin.Position = new Position(pin.Position.Latitude, lng), pin.Position.Longitude, position.Longitude) }
      // Play the animation over 2000ms with a new frame every 16ms
      }.Commit(map, "PinAnimation", 16, 2000, Easing.SinInOut, (v, c) => {
          // If the animation is cancelled for any reason, update the pin position to the target value
          if (c) {
              pin.Position = position;
          }
      
          // Optionally, pan the map to the new position after the animation is complete
          var mapSpan = new MapSpan(position, 0.01, 0.01);
          map.MoveToRegion(mapSpan);
      }, () => false);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-23
        • 1970-01-01
        • 2020-07-22
        • 2022-10-15
        • 2020-04-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多