Question

I created a new Windows Phone 8 Project in Visual Studio, then I used the Map Control to show it in the default Content Panel Grid.

When I tap on any place in my map control I want to retrieve the Long and Lat and display the values in a Message Box.

<Grid x:Name="Content_Panel" Grid.Row="1" Margin="12,0,12,0">
    <Controls:Map />
</Grid>
Was it helpful?

Solution

Try to add Tap event handler to your map control :

<Controls:Map x:Name="MyMap" Tap="MyMap_Tap"/>

Then you can use ConvertViewportPointToGeoCoordinate method to convert tapped point to coordinate :

private void MyMap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
     GeoCoordinate location = MyMap.ConvertViewportPointToGeoCoordinate(e.GetPosition(MyMap));
     MessageBox.Show("latitude : {1}, longitude : {0}",
                        location.Latitude,
                        location.Longitude);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top