繁体   English   中英

在Windows Phone 8.1 C#中将地址转换为纬度和经度

[英]Converting an address into latitude and longitude in windows phone 8.1 c#

我想从地址中获取经度和纬度。

Geolocator geo = new Geolocator();
try
{
    Geoposition geoposition1 = await geo.GetGeopositionAsync(
        maximumAge: TimeSpan.FromMinutes(5),
        timeout: TimeSpan.FromSeconds(10));

    //With this 2 lines of code, the app is able to write on a Text Label the Latitude and the Longitude, given by {{Icode|geoposition}}
    //location1.Text = "GPS:" + geoposition.Coordinate.Latitude.ToString("0.00") + ", " + geoposition.Coordinate.Longitude.ToString("0.00");
}
//If an error is catch 2 are the main causes: the first is that you forgot to include ID_CAP_LOCATION in your app manifest. 
//The second is that the user doesn't turned on the Location Services
catch (Exception ex)
{
    //exception
}
// find the address of the tapped location
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(geopoint);

// If successful then display the address.
if (result.Status == MapLocationFinderStatus.Success)
{
    if (result.Locations.Count > 0)
    {
        string display;
        if (string.IsNullOrEmpty(result.Locations[0].Address.Street))
        {
            display = result.Locations[0].Address.Town + ", " +
            result.Locations[0].Address.Region;
        }
        else
        {
            display = result.Locations[0].Address.StreetNumber + " " +
            result.Locations[0].Address.Street;
        }

        tbAddress.Text = display;
        //tbAddress1.Text = display;
    }
    else
    {
        // string msg = this.resourceLoader.GetString("NoAddress");
        // tbAddress.Text = msg;
    }
}

这是我当前实现的,现在我希望存储在display的位置显示在其他两个文本块中。 感谢您的任何建议。

我会添加类似的内容:

display += " Latitude: " + result.Locations[0].Point.Position.Latitude.ToString();
display += " Longitude: " + result.Locations[0].Point.Position.Longitude.ToString();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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