MapControl 获取点击位置 UWP

MapControl get tapped location UWP

我的应用程序中有一个 MapControl,我想检索用户记录的点的坐标。

<Maps:MapControl    Grid.Row="0" 
                    ColorScheme="Light" 
                    Margin="10" 
                    x:Name="mainMap" 
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    Tapped="mainMap_Tapped"
                    MapElementClick="mainMap_MapElementClick"
                />

但是我不知道如何从事件中得到这个private void mainMap_Tapped(object sender, TappedRoutedEventArgs e)

GeoPoint geoPt = this.mainMap.Layers[0].ScreenToGeoPoint(e.GetPosition(this.mapControl1)); 

应该给你定位点。

要获取MapControl中点击的位置,我们可以使用MapControl.MapTapped event. This event occurs when the user taps the MapControl or clicks on it with the left mouse button. An instance of MapInputEventArgs provides data for this event. And in MapInputEventArgs, we can get the location with MapInputEventArgs.Location property。例如:

在XAML中:

<Maps:MapControl x:Name="mainMap"
                 Grid.Row="0"
                 Margin="10"
                 HorizontalAlignment="Stretch"
                 VerticalAlignment="Stretch"
                 ColorScheme="Light"
                 MapTapped="mainMap_MapTapped"
                 MapElementClick="mainMap_MapElementClick" />

在代码隐藏中:

private void mainMap_MapTapped(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
{
    var tappedGeoPosition = args.Location.Position;
    string status = "MapTapped at \nLatitude:" + tappedGeoPosition.Latitude + "\nLongitude: " + tappedGeoPosition.Longitude;
    rootPage.NotifyUser( status, NotifyType.StatusMessage);
}