Windows phone 7 WP7-必应地图-如何处理MapItemsControl上的多个图钉?-当前正在崩溃的应用程序
当我拖动或缩放时,我的bing地图应用程序最终崩溃。在模拟器和设备上测试 我已经安装了10月份的更新 MapItemsControl绑定到ObservableCollection。 应用程序启动时,引脚已加载且可见 在进行故障排除时,我确定如果地图上的图钉位于相同的常规区域,应用程序不会崩溃。例如Windows phone 7 WP7-必应地图-如何处理MapItemsControl上的多个图钉?-当前正在崩溃的应用程序,windows-phone-7,bing-maps,Windows Phone 7,Bing Maps,当我拖动或缩放时,我的bing地图应用程序最终崩溃。在模拟器和设备上测试 我已经安装了10月份的更新 MapItemsControl绑定到ObservableCollection。 应用程序启动时,引脚已加载且可见 在进行故障排除时,我确定如果地图上的图钉位于相同的常规区域,应用程序不会崩溃。例如 addPin("40.78184126814031", "-73.97712707519532"); addPin("40.74569634433956", "-73.967170715332
addPin("40.78184126814031", "-73.97712707519532");
addPin("40.74569634433956", "-73.96717071533204");
addPin("40.7117682299881", "-74.0125322341919");
addPin("40.75777392583087", "-73.96950960159302");
addPin("42.35960626034072", "-71.09212160110473");
addPin("51.388066116760086", "30.098590850830067");
addPin("48.17972265679143", "11.54910385608672");
addPin("40.28802528051879", "-76.65668606758117");
但是,如果pin分散开来,当用户放大到一个特定pin和/或拖动地图时,应用程序就会崩溃。例如
addPin("40.78184126814031", "-73.97712707519532");
addPin("40.74569634433956", "-73.96717071533204");
addPin("40.7117682299881", "-74.0125322341919");
addPin("40.75777392583087", "-73.96950960159302");
addPin("42.35960626034072", "-71.09212160110473");
addPin("51.388066116760086", "30.098590850830067");
addPin("48.17972265679143", "11.54910385608672");
addPin("40.28802528051879", "-76.65668606758117");
不确定项目代码是否必要-我假设有一些我不知道的概念
有什么建议吗?我洗耳恭听。
堆栈跟踪如下
谢谢
Unspecified error
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.UIElement_HitTestPoint(UIElement element, Point ptHit)
at System.Windows.UIElement.HitTest(Point point)
at System.Windows.Media.VisualTreeHelper.FindElementsInHostCoordinates(Point intersectingPoint, UIElement subtree)
at Microsoft.Phone.Controls.Maps.Core.TouchHelper.<InputHitTest>d__0.MoveNext()
at Microsoft.Phone.Controls.Maps.Core.TouchHelper.HitTestAndRaiseDownEvent(UIElement root, TouchPoint touchPoint)
at Microsoft.Phone.Controls.Maps.Core.TouchHelper.TouchFrameReported(Object sender, TouchFrameEventArgs e)
at System.Windows.Input.Touch.OnTouch(Object sender, TouchFrameEventArgs e)
at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)
MAINPAGE.xaml.cs
namespace BugCrash
{
public partial class MainPage : PhoneApplicationPage
{
private ObservableCollection<PinData> _pinsA = new ObservableCollection<PinData>();
public ObservableCollection<PinData> PinsA { get { return this._pinsA; } }
// Constructor
public MainPage()
{
InitializeComponent();
this.DataContext = this;
myMap.Center = new GeoCoordinate(40.74569634433956, -73.96717071533204);
myMap.ZoomLevel = 4;
MessageBox.Show(loadAPins_fromString());
}
//ADD PIN TO COLLECTION
private void addPin(String lat, String lon)
{
PinData tmpPin;
tmpPin = new PinData() { PinLocation = new GeoCoordinate(System.Convert.ToDouble(lat), System.Convert.ToDouble(lon)) };
_pinsA.Add(tmpPin);
}
//LOAD PINS ONE BY ONE
private string loadAPins_fromString()
{
//BAD
addPin("42.35960626034072", "-71.09212160110473");
addPin("51.388066116760086", "30.098590850830067");
addPin("48.17972265679143", "11.54910385608672");
addPin("40.28802528051879", "-76.65668606758117");
return "A PINS LOADED - STRING";
}
}
}
名称空间错误崩溃
{
公共部分类主页:PhoneApplicationPage
{
私有ObservableCollection_pinsA=新ObservableCollection();
公共ObservableCollection PinsA{get{返回此。\u PinsA;}}
//建造师
公共主页()
{
初始化组件();
this.DataContext=this;
myMap.Center=新地理坐标(40.74569634433956,-73.96717071533204);
myMap.ZoomLevel=4;
Show(loadAPins_fromString());
}
//将PIN添加到集合中
专用void addPin(字符串横向、字符串纵向)
{
PinData-tmpPin;
tmpPin=new PinData(){PinLocation=new geocordination(System.Convert.ToDouble(lat),System.Convert.ToDouble(lon));
_pinsA.Add(tmpPin);
}
//逐个加载销
私有字符串loadAPins\u fromString()
{
//坏的
addPin(“42.35960626034072”,“-71.092160110473”);
addPin(“51.388066116760086”、“30.09859085083067”);
addPin(“48.17972265679143”、“11.54910385608672”);
addPin(“40.28802528051879”,“-76.65668606758117”);
返回“A引脚加载-字符串”;
}
}
}
MAINPAGE.xaml
<phone:PhoneApplicationPage
x:Class="BugCrash.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False"
xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps">
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--RESOURCES-->
<Grid.Resources>
<my:ApplicationIdCredentialsProvider ApplicationId="XX" x:Key="MyCredentials"/>
</Grid.Resources>
<my:Map Height="768"
Name="myMap"
VerticalAlignment="Top" Width="480"
CredentialsProvider="{StaticResource MyCredentials}">
<my:Map.Mode>
<my:AerialMode ShouldDisplayLabels="True" />
</my:Map.Mode>
<my:MapItemsControl
x:Name="GroupAPins"
ItemsSource="{Binding PinsA}"
>
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:Pushpin Location="{Binding PinLocation}" Width="60" Height="55" Content="PIN">
</my:Pushpin>
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:Map>
</Grid>
</phone:PhoneApplicationPage>
我不得不去微软寻求答案。 原来地图控件中有bug。 为了避免这个错误,动态加载bing地图控件 变化如下:
public MainPage()
{
InitializeComponent();
this.DataContext = this;
//Create a map.
Map MyMap = new Map();
MyMap.CredentialsProvider = new ApplicationIdCredentialsProvider("XX");
//Remove the List of items from the resource and add it to the map
this.LayoutRoot.Resources.Remove("GroupAPins");
MyMap.Children.Add(GroupAPins);
MyMap.Center = new GeoCoordinate(40.74569634433956, -73.96717071533204);
MyMap.ZoomLevel = 5;
//Add the map to the content panel.
ContentPanel.Children.Add(MyMap);
loadAPins_fromString();
}
还有XAML
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--RESOURCES-->
<Grid.Resources>
<DataTemplate x:Key="LogoTemplate">
<my:Pushpin Location="{Binding PinLocation}" />
</DataTemplate>
<my:MapItemsControl x:Name="GroupAPins"
ItemTemplate="{StaticResource LogoTemplate}"
ItemsSource="{Binding PinsA}">
</my:MapItemsControl>
</Grid.Resources>
<Grid x:Name="ContentPanel" Grid.Row="0" Margin="12,0,12,0"/>
</Grid>
Ahhh代码编写。
事实证明,我可以通过移除图钉的宽度和高度来防止应用程序崩溃
微软的解决方案没有包括图钉宽度和高度,所以我假设动态创建地图控件就是答案,但是添加了宽度和高度,和我原来的应用程序一样崩溃
我需要使用XAML中的地图控件将代码更改回原始版本-并删除图钉宽度和高度,以查看它是否解决了这两个版本-但这似乎是问题所在-我的应用程序现在运行良好-动态创建的地图控件-图钉没有宽度或高度
无论如何,希望这能帮助别人
-D我刚让我的应用程序抛出此异常。我没有设置图钉的宽度或高度,尽管图钉确实有按钮作为设置了BorderThickness=“0”Padding=“0”的子控件。对我没有帮助。。。但我的应用程序还是崩溃了。