MapControl获取位置UWP

时间:2016-07-27 15:31:27

标签: c# uwp uwp-xaml uwp-maps

我的应用程序中有一个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)

中获取此信息

2 个答案:

答案 0 :(得分:2)

要在MapControl中获取点按的位置,我们可以使用 MapControl.MapTapped event 。当用户点击 MapControl 或点击鼠标左键时,就会发生此事件。 MapInputEventArgs 的实例提供此事件的数据。在MapInputEventArgs中,我们可以使用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);
}

答案 1 :(得分:0)

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

应该找到你的地址。

相关问题