簡體   English   中英

Windows Phone 8映射:{System.ArgumentException:值不在預期范圍內。}

[英]Windows Phone 8 Map : {System.ArgumentException: Value does not fall within the expected range.}

我的XAML中有一個Map控件,如下所示:

<maps:Map x:Name="MapViewControl" Height="480">

        </maps:Map>

我在后面的代碼中填充MapLayer:

 MapLayer layer = new MapLayer();
        MapOverlay overLay;
        layer.Clear();
        foreach (var item in listOfItems)
        {
            overLay = new MapOverlay();
            overLay.GeoCoordinate = new GeoCoordinate(item.Latitude, item.Longitude);
            overLay.Content = redCircle;
            overLay.PositionOrigin = new Point(0.5, 0.5);

            layer.Add(overLay);

        }
        MapViewControl.Layers.Add(layer);

編輯:上面的代碼是頁面上的Load事件。

我收到“值未在預期范圍內”的錯誤。

任何想法?

我想到了。 問題是redCircle(:))。 這是對我創建的橢圓形狀的引用。 不知道Mapping框架不喜歡在所有疊加層中引用相同的Content實例。

之前:

 overLay.Content = redCircle;

之后(即現在):

overLay.Content = CreateShape();

其中CreateShape定義為:

 private Ellipse CreateShape()
    {
        Ellipse redCircle = new Ellipse();
         redCircle.Width = 10;
         redCircle.Height = 10;
         redCircle.Fill = new SolidColorBrush(Colors.Red);
         return redCircle;
    }

因此,每次在循環中都會創建它。

GeoCoordinate()的構造函數期望參數的值從-90.0到90.0。如果不滿足此條件,則會拋出ArgumentOutOfRangeException

您可以驗證item.Latituteitem.Longitude的值嗎?

如果不是,請進行調試並逐行檢查錯誤發生的位置。 或提供您的listOfItems實例的一些示例值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM