在windows phone 8.1 c#中将地址转换为纬度和经度
本文关键字:转换 地址 纬度 经度 phone windows | 更新日期: 2023-09-27 17:53:54
我想从地址中获取经纬度
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();