我正在开发 Windows Phone 8 应用程序,但我找不到如何从地址获取坐标。
问题是,我有我的坐标,我需要计算我和某个地址之间的距离。
Windows Phone 8 没有太多记录,所以请帮助我。
您正在寻找的称为“地理编码”:将地址转换为地理坐标。
正如之前提到的,您可以在 WP7 上使用 Google 和 Bing 来实现这一目标。在 Windows Phone 8 上,地理编码和反向地理编码作为框架的一部分受到支持。您可以阅读地理编码概述在这篇诺基亚介绍文章中(在“地理编码”下)和更全面的概述在另一篇诺基亚文章中.
以下是从地址转换为坐标的地理编码示例:
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());
}
当我在 WP8 上运行此代码片段时,我收到以下消息框:
![MEssageBox showing details for the ferry building](https://i.stack.imgur.com/KJkHU.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)