简体   繁体   中英

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.

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.

As shown below I've used a foreach method to get the Bing Maps children, which then allowed me to work with it.

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

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

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

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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