我正在开发 Windows Phone 8 应用程序,但我找不到如何从地址获取坐标。 问题是,我有我的坐标,我需要计算我和某个地址之间的距离。
windows phone 8 的文档不多,所以请帮助我。
最佳答案
您要查找的内容称为“地理编码”:将地址转换为地理坐标。
如前所述,您可以在 WP7 上使用 Google 和 Bing 来实现这一点。在 Windows Phone 8 上,作为框架的一部分支持地理编码和反向地理编码。您可以阅读地理编码概述 at this Nokia intro article (在“地理编码”下)和更全面的概述 at this other Nokia article .
这是一个从地址到坐标的地理编码示例:
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 上运行此代码片段时,我收到以下消息框:
关于c# - 如何从街道地址获取坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14457247/