in Windows Phone 8 When I Tap in any place in map i retrive Lattitude and Longitude and Specific location name

StackOverflow https://stackoverflow.com/questions/23109513

Question

I have in my windows-phone-8 project.

XAML Code:

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

and when tap event fire i can get Long and Lat in Message Box Like This

C# Code:

private void MyMap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    GeoCoordinate location = MyMap.ConvertViewportPointToGeoCoordinate(e.GetPosition(MyMap));
    MessageBox.Show("latitude :" + location.Latitude +", longitude : " + location.Longitude);
}

I need to get also the name of this position in addation to it's Long and Lat, so how can i do this.

Thanks

Was it helpful?

Solution

You may use reverse Geocoding converting from a coordinate to an address:

private void Maps_ReverseGeoCoding(object sender, RoutedEventArgs e)
{
    ReverseGeocodeQuery query = new ReverseGeocodeQuery()
    {
        GeoCoordinate = new GeoCoordinate(YourLatitude, YourLongitude)
    };
    query.QueryCompleted += query_QueryCompleted;
    query.QueryAsync();
}

void query_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
    StringBuilder placeString = new StringBuilder();
    foreach (var place in e.Result)
    {
        placeString.AppendLine(place.GeoCoordinate.ToString());
        placeString.AppendLine(place.Information.Name);
        placeString.AppendLine(place.Information.Description);
        placeString.AppendLine(place.Information.Address.BuildingFloor);
        placeString.AppendLine(place.Information.Address.BuildingName);
        placeString.AppendLine(place.Information.Address.BuildingRoom);
        placeString.AppendLine(place.Information.Address.BuildingZone);
        placeString.AppendLine(place.Information.Address.City);
        placeString.AppendLine(place.Information.Address.Continent);
        placeString.AppendLine(place.Information.Address.Country);
        placeString.AppendLine(place.Information.Address.CountryCode);
        placeString.AppendLine(place.Information.Address.County);
        placeString.AppendLine(place.Information.Address.District);
        placeString.AppendLine(place.Information.Address.HouseNumber);
        placeString.AppendLine(place.Information.Address.Neighborhood);
        placeString.AppendLine(place.Information.Address.PostalCode);
        placeString.AppendLine(place.Information.Address.Province);
        placeString.AppendLine(place.Information.Address.State);
        placeString.AppendLine(place.Information.Address.StateCode);
        placeString.AppendLine(place.Information.Address.Street);
        placeString.AppendLine(iplaceem.Information.Address.Township);
    }
    MessageBox.Show(placeString.ToString());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top