如何在窗口电话sdk上通过经度和纬度获取街道或地址的名称

时间:2014-03-14 09:56:02

标签: c# windows-phone-8

C# - 如果我们知道经度和纬度,请告诉我如何获取街道或地址的名称。

1 个答案:

答案 0 :(得分:2)

使用ReverseGeoCoding,它可以作为windows phone 8版本中sdk的一部分提供

反向地理编码采用纬度和经度,并返回地球中这些点的字符串地址或位置。

检查this链接

this也是

原始用法

ReverseGeocodeQuery reverseGeocode = new ReverseGeocodeQuery();
reverseGeocode.GeoCoordinate = new GeoCoordinate(gCordinate.Latitude, gCordinate.Longitude);
reverseGeocode.QueryCompleted += reverseGeocode_QueryCompleted;
reverseGeocode.QueryAsync();

void reverseGeocode_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
    try
    {
        if (e.Cancelled)
        {
            txtCompleteAddress.Text = "operation was cancelled";
        }
        else if (e.Error != null)
        {
            txtCompleteAddress.Text = "Error: " + e.Error.Message;
        }
        else if (e.Result != null)
        {
            if (e.Result.Count > 0)
            {
                MapAddress geoAddress = e.Result[0].Information.Address;
                addressString1 = geoAddress.HouseNumber + " " + geoAddress.Street;
                addressString2 = geoAddress.District + ", " + geoAddress.City;
                addressString3 = geoAddress.Country;
                if (addressString1 != " ")
                    addressString1 = addressString1 + "\n";
                else
                    addressString1 = "";

                if (addressString2 != ",  ")
                    addressString2 = addressString2 + "\n";
                else
                    addressString2 = "";

                txtCompleteAddress.Text = addressString1 + addressString2 + addressString3;
            }
            else
            {
                txtCompleteAddress.Text = "no address found at that location";
            }
        }
    }
    catch
    {
        MessageBox.Show("Some error occured in converting location geo Coordinates to location address, please try again later");
    }
}