Rok*_* H. 2 c# location windows-phone-8
我正在使用Windows Phone 8应用程序,但我找不到,如何获取坐标表格地址.问题是,我有我的coordiantes,我需要计算我和一些地址之间的距离.
Windows Phone 8没有记录那么多,所以请帮帮我.
您正在寻找的是"地理编码":将地址转换为GeoCoordinate.
如前所述,您可以在WP7上使用Google和Bing来实现这一目标.在Windows Phone 8上支持地理编码和反向地理编码作为框架的一部分.您可以在此诺基亚简介文章("地理编码"下)阅读GeoCoding概述,并在此诺基亚其他文章中查看更全面的概述.
以下是地理编码从地址转换为坐标的示例:
private void Maps_GeoCoding(object sender, RoutedEventArgs e)
{
GeocodeQuery query = new GeocodeQuery()
{
GeoCoordinate = new GeoCoordinate(0, 0),
SearchTerm = "Ferry Building, San-Francisco"
};
query.QueryCompleted += query_QueryCompleted;
query.QueryAsync();
}
void query_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Ferry Building Geocoding results...");
foreach (var item in e.Result)
{
sb.AppendLine(item.GeoCoordinate.ToString());
sb.AppendLine(item.Information.Name);
sb.AppendLine(item.Information.Description);
sb.AppendLine(item.Information.Address.BuildingFloor);
sb.AppendLine(item.Information.Address.BuildingName);
sb.AppendLine(item.Information.Address.BuildingRoom);
sb.AppendLine(item.Information.Address.BuildingZone);
sb.AppendLine(item.Information.Address.City);
sb.AppendLine(item.Information.Address.Continent);
sb.AppendLine(item.Information.Address.Country);
sb.AppendLine(item.Information.Address.CountryCode);
sb.AppendLine(item.Information.Address.County);
sb.AppendLine(item.Information.Address.District);
sb.AppendLine(item.Information.Address.HouseNumber);
sb.AppendLine(item.Information.Address.Neighborhood);
sb.AppendLine(item.Information.Address.PostalCode);
sb.AppendLine(item.Information.Address.Province);
sb.AppendLine(item.Information.Address.State);
sb.AppendLine(item.Information.Address.StateCode);
sb.AppendLine(item.Information.Address.Street);
sb.AppendLine(item.Information.Address.Township);
}
MessageBox.Show(sb.ToString());
}
Run Code Online (Sandbox Code Playgroud)
当我在WP8上运行此代码片段时,我得到以下消息框:
