Reputation: 113
I am creating an app in UWP that makes heavy use of the built-in MapControl object to display icons and images. My next functionality in the app will require extracting the gps location of where the user clicks on the map to edit the location of a map icon. So, the user uses their mouse (or finger) to click on the map at a certain location, I need a tapped event to fire which knows the geolocation of the click. I do not which API I should be looking into.
I know it has to be posible, the windows 10 included maps app determines the address of any location you click on. How do I implement a similar functionality?
Mock code...
xaml:
<Maps:MapControl x:Name="map_main" Loaded="MapLoaded" MapTapped="MapUserTapped"/>
c#:
private void MapUserTapped(MapControl sender, MapInputEventArgs args)
{
if (!edit_mode) { return; }
//no idea how to do this part, are there any api's for this?
Geoposition geopos_edit_position = map_main.TapLocation;
EditMapIconPosition(geopos_edit_position);
}
private void EditMapIconPosition(Geoposition geopos_edit_position)
{
...
}
Upvotes: 0
Views: 938
Reputation: 113
Well I figured it out. Seems I just had to do a little digging into the MapTapped event and the parameters it gives. The code is very simple, as follows.
private void MapUserTapped(MapControl sender, MapInputEventArgs args)
{
if (!edit_mode) { return; }
//to get a basicgeoposition of wherever the user clicks on the map
BasicGeoposition basgeo_edit_position = args.Location.Position;
//just checking to make sure it works
Debug.WriteLine("tapped - lat: " + basgeo_edit_position.Latitude.ToString() + " lon: " + basgeo_edit_position.Longitude.ToString());
EditMapIconPosition(basgeo_edit_position);
}
Upvotes: 1
Reputation: 55
Try using Cursor.Position to get where user is clicking in your MapUserTapped event.
Upvotes: 0