none
GeoPosition on Mouse Click RRS feed

  • Question

  • I was wondering if anyone has an example of how to extract the geoposition(Lat,Lon) from a mouse click on the Bing Maps control. Pretty much I am launching the maps control, and I need to be able to take the Coordinates that are chosen via mouse click(double click) and pass them back into my UWP app.
    Thursday, May 17, 2018 9:22 PM

Answers

  • 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:

    In XAML:

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

    In code-behind:

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



    [Blog] [twitter] [LinkedIn]

    Friday, May 18, 2018 4:51 PM