如何通过经度和纬度在窗口手机sdk上获得街道或地址的名称

本文关键字:街道 地址 sdk 经度 何通过 纬度 手机 窗口 | 更新日期: 2023-09-27 17:50:11

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

如何通过经度和纬度在窗口手机sdk上获得街道或地址的名称

使用ReverseGeoCoding,这是windows phone os版本8中可用的sdk的一部分

反向地理编码接受纬度和经度,并返回这些点在地球上的字符串地址或位置。

查看此链接

原始使用

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");
    }
}