简体   繁体   中英

How to get name of street or address via Longitude and Latitude on window phone sdk

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

Using ReverseGeoCoding, which is available as a part of the sdk in windows phone os version 8

Reverse Geo Coding takes the latitude and longitude and returns the string address or location of those points in the globe.

check this link

and this also

Raw usage

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM