【问题标题】:Make a pushpin move smoothly on MapControl Windows phone 8.1在 MapControl Windows phone 8.1 上使图钉平滑移动
【发布时间】:2015-03-26 10:06:16
【问题描述】:

我正在尝试创建一个跟踪我当前位置的应用程序。这是我的代码:

private Image currentLocationPin;
private async void CurrentLocationChanged(Geolocator sender, PositionChangedEventArgs args)
    {
        await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            mapControl.Children.Remove(currentLocationPin);
            currentLocationPin = new Image() { Source = new BitmapImage(new Uri(smallIconURI)) };
            var currentGeo = new Geopoint(new BasicGeoposition
            {
                Latitude = args.Position.Coordinate.Point.Position.Latitude,
                Longitude = args.Position.Coordinate.Point.Position.Longitude
            });

            MapControl.SetNormalizedAnchorPoint(currentLocationPin, new Point(0.5, 1));
            MapControl.SetLocation(currentLocationPin, currentGeo);
            mapControl.Children.Add(currentLocationPin);

            currentLocationPin.Tapped += ChildObj_Tapped;
            mapControl.LandmarksVisible = false;
            mapControl.TrafficFlowVisible = false;
            mapControl.PedestrianFeaturesVisible = false;
            currentGeopoint = currentGeo;
        });
    }

当我当前的位置改变时,这个函数会被调用。它工作得很好,但是这个问题。因为我删除了前一个引脚然后添加了一个新引脚,所以当我在地图上看到它时,每 2 个引脚之间有一个延迟。我尝试使用 MapIcon,但它也不起作用。我试图不删除别针并仅更新其位置,但在旧别针旁边会有一个新别针。 谢谢。

【问题讨论】:

  • 你找到解决办法了吗?

标签: c# xaml dictionary windows-phone-8.1


【解决方案1】:

您不必在每次位置更改时都删除-重新创建-添加叠加层。更新现有叠加层的位置应该可以解决问题(尽管听起来您尝试过但没有用?)

我尚未对此进行测试,但我调整了您的代码以更新现有叠加层的位置,而不是重新创建它。

    await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        // If needed, create the location pin.
        if(currentLocationPin == null)
        {
            currentLocationPin = new Image() { Source = new BitmapImage(new Uri(smallIconURI)) };
            MapControl.SetNormalizedAnchorPoint(currentLocationPin, new Point(0.5, 1));
            mapControl.Children.Add(currentLocationPin);
        }

        // Update the pin's location.  

        var currentGeo = new Geopoint(new BasicGeoposition
        {
            Latitude = args.Position.Coordinate.Point.Position.Latitude,
            Longitude = args.Position.Coordinate.Point.Position.Longitude
        });

        MapControl.SetLocation(currentLocationPin, currentGeo);

        mapControl.LandmarksVisible = false;
        mapControl.TrafficFlowVisible = false;
        mapControl.PedestrianFeaturesVisible = false;
        currentGeopoint = currentGeo;
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多