我的应用程序中有一个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)
答案 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));
应该找到你的地址。