I want to add pushpins to my MapControl that can be tapped. Since Windows 8.1 pushpin class is no longer available and UWP offers us something called ImageIcon(imo its kinda crappy). Here's my code:
BasicGeoposition bg = new BasicGeoposition() { Latitude = 52.280, Longitude = 20.972 };
Geopoint snPoint = new Geopoint(bg);
MapIcon mapIcon1 = new MapIcon();
mapIcon1.Location = snPoint;
mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
MyMap.MapElements.Add(mapIcon1);
How can I make it event handling(like tap or click)?
Thank you in advance
In UWP you can put much more elements in the map and click event is handled little different way - take a look at MapControl.MapElementClick. Events are handled by MapControl - so you don't need to subscribe in every map's element - the mentioned event will return list of clicked elements. The sample code can look like this:
<map:MapControl Name="MyMap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MapElementClick="MyMap_MapElementClick"/>
private void MyMap_MapElementClick(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapElementClickEventArgs args)
{
MapIcon myClickedIcon = args.MapElements.FirstOrDefault(x => x is MapIcon) as MapIcon;
// do rest
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With