我一直在努力使用地图控件(不是Bing地图)在Windows Phone 8应用程序中的地图上显示多个图钉。这是我的代码:
void webClient_PlacesNearbyDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(e.Result))
{
MapLayer NearbyPlacesLayer = new MapLayer();
Image Pushpin = new Image();
Pushpin.Source = new BitmapImage(new Uri("/Assets/Icons/pushpin.png", UriKind.RelativeOrAbsolute));
Pushpin.Width = 26;
Pushpin.Height = 26;
Pushpin.Opacity = 100;
RootObject query = JsonConvert.DeserializeObject<RootObject>(e.Result);
List<Item> places = query.results.items.ToList();
foreach (Item item in places)
{
Debug.WriteLine(item.position[0]);
Debug.WriteLine(item.position[1]);
MapOverlay MyOverlay = new MapOverlay();
MyOverlay.Content = Pushpin;
MyOverlay.GeoCoordinate = new GeoCoordinate(item.position[0], item.position[1]);
MyOverlay.PositionOrigin = new Point(0.0, 1.0);
NearbyPlacesLayer.Add(MyOverlay);
}
Map.Layers.Add(NearbyPlacesLayer);
}
}
catch (Exception ex)
{
MessageBox.Show("Oops");
}
finally
{
ProgressBar.Visibility = Visibility.Collapsed;
}
}
然而,这段代码崩溃了应用程序并说:
程序&#39; [1904] TaskHost.exe&#39;已退出代码-1 (0xFFFFFFFF的)。
我无法弄清楚似乎是什么问题。需要你的建议。
P.S。两行Debug.WriteLine
为列表中的每个项目写下正确的坐标。