MapControl 获取点击位置 UWP [英] MapControl get tapped location UWP

查看:33
本文介绍了MapControl 获取点击位置 UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a MapControl in my app and I want to retrieve the coordinate of the point taped by the user.

<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)

But I don't know how to get this from the event private void mainMap_Tapped(object sender, TappedRoutedEventArgs e)

推荐答案

要在 MapControl 中获取点击位置,我们可以使用 MapControl.MapTapped 事件.当用户点击 MapControl 或用鼠标左键单击它.MapInputEventArgs 提供此事件的数据.在 MapInputEventArgs 中,我们可以通过 MapInputEventArgs.Location 属性.例如:

To get the tapped location in MapControl, we can use 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. For example:

在 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);
}

这篇关于MapControl 获取点击位置 UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆