Add Pushpin to MapControl in UWP
Asked Answered
B

1

5

I'd like to add a Pushpin to a MapControl in a Windows 10 app, but it seems the control is gone since Windows 8.1.

Pushpin

It was as simple as that:

Pushpin locationPushpin = new Pushpin();                      
locationPushpin.Background = new SolidColorBrush(Colors.Purple);
locationPushpin.Content = "You are here";
locationPushpin.Tag = "locationPushpin";
locationPushpin.Location = watcher.Position.Location;
this.map.Children.Add(locationPushpin);
this.map.SetView(watcher.Position.Location, 18.0);

But Pushpin type is not recognized anymore...

Bumkin answered 7/11, 2015 at 9:1 Comment(0)
I
7

Map control has changed little in UWP - take a look at Windows.UI.Xaml.Controls.Maps namespace.

As for adding Pushpins (POIs), you can do it in couple of ways. For example:

// get position
Geopoint myPoint = new Geopoint(new BasicGeoposition() { Latitude = 51, Longitude = 0 });
//create POI
MapIcon myPOI = new MapIcon { Location = myPoint, NormalizedAnchorPoint = new Point(0.5, 1.0), Title = "My position", ZIndex = 0 };
// add to map and center it
myMap.MapElements.Add(myPOI);
myMap.Center = myPoint;
myMap.ZoomLevel = 10;

For more guidelines visit MSDN.

Impatience answered 7/11, 2015 at 9:25 Comment(5)
Is it possible to drag this MapIcon and get the location when user drops the MapIcon at some latitude and longitude?Langur
@KinjanBhavsar I haven't played with that much yet, but I would search in MapControl class and its events.Impatience
Will search the same.Langur
Checked the Events of MapControl got one CenterChanged - Occurs when the value of the Center property of the MapControl changes. Will it be helpful?Langur
@KinjanBhavsar I think it may be - give it a try.Impatience

© 2022 - 2024 — McMap. All rights reserved.