c# - 如何从街道地址获取坐标

标签 c# location windows-phone-8

我正在开发 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 上运行此代码片段时,我收到以下消息框:

MEssageBox showing details for the ferry building

关于c# - 如何从街道地址获取坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14457247/

相关文章:

c# - 在参数 c# 中使用 this 关键字

c# - datagridview 单元格编辑和保存 Windows 窗体中的功能?

Android:每次使用一次获取即时位置的最佳方式

c# - 保存前操作视频帧

c# - 了解 Windows Phone 开发中的数据绑定(bind)

c# - 使用 C# 从 asp.net 中的代码后面将文本加载到 textarea

c# - AutoMapper C# - 为目标中所有未映射的字符串设置默认值

javascript - 根据位置(IP 地址)将用户重定向到不同的网站

ios - 如何在 Swift LocationPicker 库中只搜索学校

Windows phone 7 新 Windows phone 8 操作系统版本中的应用程序