Search code examples
event-handlingmapswin-universal-apppushpinuwp-maps

How to get the geocode of a specific location by tapping on the map UWP C#


I went through lot of tutorials which states how to add a mapicon a pushpin on to a map, but all of them require me to hard code the latitude and the longitude or give the address in a text form.

But what i want is to get the geocode (lat and lon values) of any place when and where the user double tap on the map.
Adding a pushpin there is required too.
i am not using bing maps api, using services.maps, Devices.geolocation, map control and other uwp map functionalities only.


Solution

  • What you need to handle is the MapTapped of the MapControl event to get the geolocation of the place where the pointer is tapped. Something like this would do:

    private void MyMap_MapTapped(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
    {
        var tappedGeoPosition = args.Location.Position;
        //Do something
    }
    

    Check out these official samples on GitHub