简体   繁体   English

必应地图,是否可以从MapLayer子级检索位置?

[英]Bing Maps, retrieve locations from MapLayer children?

I'm using Bing maps with WPF and C# and I'm trying to retrieve the children that were added into the map, primarily to get their coordinates to save into the database and calculate distance between two children on different map controls. 我将Bing地图与WPF和C#结合使用,并且试图检索添加到地图中的子项,主要是为了将其坐标保存到数据库中并计算不同地图控件上两个子项之间的距离。

Below is how I'm adding the child 'pushpin' into one of the maps. 下面是我如何将儿童“图钉”添加到其中一张地图中。

bmMapdestination.Children.Clear();
e.Handled = true;
var mousePosition = e.GetPosition(bmMapdestination);
Location pinLocation = bmMapdestination.ViewportPointToLocation(mousePosition);
Pushpin pin = new Pushpin() { Location = pinLocation , Name = "DestPin"};
bmMapdestination.Children.Add(pin);
CalculateDistance();

After a couple of days coding I've come up with a bit of code to retrieve pushpins from the Bing Maps control that works how I wanted it to, this works fine when extracting for one pushpin per map, but I'm sure it could be useful for more than one. 经过几天的编码,我想出了一些代码从Bing Maps控件中检索图钉,该控件可以按我的意愿工作,当为每个地图提取一个图钉时,此方法很好用,但是我敢肯定,可以多于一个。

As shown below I've used a foreach method to get the Bing Maps children, which then allowed me to work with it. 如下所示,我使用了foreach方法来获取Bing Maps子级,然后使我可以使用它。

public void CalculateDistance()
        {
            Location pinLocation = new Location();

            foreach(Pushpin pin in bmMapdestination.Children)
            {
                pinLocation = pin.Location;
            }

            txtEditPickUpEditLocation.Text = pinLocation.Latitude.ToString()+","+pinLocation.Longitude.ToString();

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM