我正在尝试在Windows Phone应用程序上使用Bing Maps控件,但是当我启动地图控件所在的页面时,我收到此错误:
Failed to create a 'System.Device.Location.GeoCoordinate' from the text '0,0'. [Line: 32 Position: 58]
这是我的XAML,虽然这里没什么特别的:
<my:Map Height="224"
HorizontalAlignment="Left"
Margin="7,4,0,0"
Name="map1"
VerticalAlignment="Top"
Width="443"
Loaded="map1_Loaded"
ViewChangeStart="map1_ViewChangeStart">
<my:MapLayer Name="lMain">
<Ellipse Fill="Red" Width="20" Height="20"
my:MapLayer.Position="0,0"
Name="ppLocation"
Visibility="Collapsed" />
</my:MapLayer>
</my:Map>
我尝试使用此代码添加坐标:
GeoCoordinate ld = (Application.Current as App).curentLocation;
Location ppLoc = new Location();
GeoCoordinate g = new GeoCoordinate();
ppLoc.Latitude = ld.Latitude;
ppLoc.Longitude = ld.Longitude;
ppLoc.Altitude = ld.Altitude;
map1.SetView(ppLoc, 10);
//update pushpin location and show
MapLayer.SetPosition(ppLocation, ppLoc);
ppLocation.Visibility = System.Windows.Visibility.Visible;
但它在map1.SetView上抛出“NullReferenceExcpetion”(ppLoc,10);
答案 0 :(得分:0)
问题是当您为my:MapLayer.Position="0,0"
设置Ellipse
时。您根本不应该设置它,或者您应该将其设置为有效坐标。
此外,当您尝试设置NullReferenceExcpetion
时,map1
因map1.SetView(ppLoc, 10);
为空而导致{。}}。