2014-03-05 71 views
-1

我在我的XAML作为地图控件:的Windows Phone 8地图:{System.ArgumentException:值没有在预期的范围之内。}

<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); 

编辑:上面的代码是页面上的加载事件。

我得到“价值不符合预期范围”的错误。

有什么想法?

+1

在哪条线上得到此异常? –

+0

@Aman一旦所有的代码得到执行。 –

回答

3

我想通了。问题是redCircle(:))。这是对我创建的椭圆形状的引用。不知何故,Mapping框架不喜欢将内容的相同实例引用到所有叠加层。

前:

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; 
    } 

因此,它被创建,每次在循环。

1

GeoCoordinate()的构造函数期望参数的值为-90.0到90.0如果您不符合此条件,则会抛出ArgumentOutOfRangeException

你可以验证item.Latituteitem.Longitude的值吗?

如果没有,请调试并逐步检查每一行,以查看发生错误的位置。或提供您的实例的一些示例值listOfItems

+0

如果listOfItems中有一个项目,它工作正常。如果有不止一个,它会吹。 –

相关问题