0

我想添加一些可以在地图上点击的图钉。首先,我想显示它们,但是当我将它们添加到地图上时,会发生 ArgumentException 并且我的应用程序崩溃了。如果我在地图上只添加一个地方,它可以工作,但是当我尝试添加更多地方时,它会崩溃。整个列表都被遍历了。

我的代码:

var myCircle = new Ellipse
                {
                    Fill = new SolidColorBrush(Colors.Blue),
                    Height = 20,
                    Width = 20,
                    Opacity = 50
                };
MapLayer locationLayer = new MapLayer();
foreach (var place in r.Result)
                {
                    //It's a method that I created to get the placecoordinate in good format because it can be with commas
                    var placeCoordinate = Geolocalisation.GetCoordinateInGoodFormat(place.Google_lat,
                                                                                    place.Google_lng);
                    if (placeCoordinate == null)
                    {
                        continue;
                    }

                    var locationOverlay = new MapOverlay
                        {
                            Content = myCircle,
                            PositionOrigin = new Point(0.5, 0.5),
                            GeoCoordinate = placeCoordinate
                        };

                    Debug.WriteLine(place.Title + ", lat: " + place.Google_lat + ", long: " + place.Google_lng);
                    //Display e.g.: soleil du midi, lat: 50.8382836, long: 4.3975321

                    locationLayer.Add(locationOverlay);

}
mapControl.Layers.Add(locationLayer); //my map in XAML

错误 :

An exception of type 'System.ArgumentException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
4

1 回答 1

1

我已经尝试为地图上的每个点创建一个新的圆实例,因为您不能将相同的 UIElement(在本例中为圆)添加到可视树两次。

      var locationOverlay = new MapOverlay
            {
                    Content = new Ellipse()
                            {
                                    Fill = new SolidColorBrush(Colors.Blue),
                                    Height = 20,
                                    Width = 20,
                                    Opacity = 50
                            },
                    PositionOrigin = new Point(0.5, 0.5),
                    GeoCoordinate = placeCoordinate
            };
于 2013-05-06T08:17:33.630 回答