WP7 - Bing 地图 - 如何处理 MapItemsControl 上的多个图钉? - 当前崩溃的应用程序

发布于 2024-10-06 23:50:27 字数 5421 浏览 0 评论 0原文

当我拖动或缩放时,我的 bing 地图应用程序最终崩溃。在模拟器和设备上进行了测试。

我已经安装了十月更新。

MapItemsControl 绑定到 ObservableCollection。 当应用程序启动时,引脚已被加载并且可见。

在进行故障排除时,我确定如果地图上的图钉位于同一区域,应用程序不会崩溃。例如,

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)

认为最好包含代码 - 运行此代码并放大崩溃应用程序 - 感谢

PINDATA 类

namespace BugCrash.models
{public class PinData{public GeoCoordinate PinLocation { get;set; }}}

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

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>

My bing map application eventually crashes when I drag or zoom. Tested on emulator and device.

I have installed the October update.

MapItemsControl binding to ObservableCollection.
When application starts, pins have been loaded and are visible.

While troubleshooting, I determine the app will not crash if the pushpins on the map are in the same general area. Example,

addPin("40.78184126814031", "-73.97712707519532");    
addPin("40.74569634433956", "-73.96717071533204");    
addPin("40.7117682299881", "-74.0125322341919");    
addPin("40.75777392583087", "-73.96950960159302");

But if the pins are spread out - the application crashes when the user zooms into one specific pin and/or dragging the map. Example,

addPin("42.35960626034072", "-71.09212160110473");    
addPin("51.388066116760086", "30.098590850830067");    
addPin("48.17972265679143", "11.54910385608672");    
addPin("40.28802528051879", "-76.65668606758117");

Not sure if the project code is necessary - I am assuming there is some concept that I just do not know about.

Any suggestions - I am all ears.
Stack trace below.

Thanks

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)

Thought it best to include the code - running this and zooming in crashes app - thanks

PINDATA class

namespace BugCrash.models
{public class PinData{public GeoCoordinate PinLocation { get;set; }}}

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏佲洛 2024-10-13 23:50:27

我必须去微软才能得到这个问题的答案。
原来地图控制有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>

I had to go to microsoft to get an answer for this.
Turns out there is bug in the map control.
To get around this bug - load the bing map control dynamically.

Changes are as follows,

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

and the 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>
分开我的手 2024-10-13 23:50:27

啊啊写代码了。
事实证明,我可以通过删除图钉的宽度和高度来防止应用程序崩溃。

微软的解决方案不包括图钉宽度和高度 - 所以我假设动态创建地图控件就是答案 - 但添加宽度和高度 - 与我的原始应用程序相同的崩溃。

我需要使用 XAML 中的地图控件将代码更改回原始版本 - 并删除图钉宽度和高度以查看它是否解决了两个版本 - 但这似乎是问题 - 我的应用程序现在运行良好 - 动态创建的地图控件 - 没有宽度或高度的图钉。

无论如何 - 希望这对某人有帮助。

-D

Ahhh code writing.
Turns out I can prevent the app from crashing by removing the width and height from the pushpin.

The Microsoft solution didn't include pushpin width and height - so I assumed creating the map control dynamically was the answer - but adding the width and height - same crash as my original app.

I need to change my code back to the original version with the map control in the XAML - and remove the pushpin width and height to see if it solves both versions - but this seems to be the problem - my app is now running fine - dynamically created map control - pushpin with no width or height.

Anyway - hope this helps someone.

-D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文