【问题标题】:how to get country name from latitude and longitude如何从纬度和经度获取国家名称
【发布时间】:2014-09-16 10:10:47
【问题描述】:

如何使用 c# 从纬度和经度中获取国家/地区名称? 我正在使用 Bing.Map API

Location location12 = new Location(location.Latitude, location.Longitude);
MapLayer.SetPosition(pin, location12);
Map.Children.Add(pin);
string placeName = GetPlaceNameForCoordinates(location.Latitude, location.Longitude);   

【问题讨论】:

  • 这是使用 Bing.Maps API 吗?在您的问题中明确说明这一点是值得的。
  • 是的,使用 Bing.Maps API

标签: c# bing-maps


【解决方案1】:

您需要使用某种反向地理编码 API。例如:

如果您已经在使用 Bing.Maps SDK,则应使用Map.SearchManager 属性获取SearchManager,然后使用ReverseGeocodeAsync 方法。特别是,如 cmets 中所述,混合和匹配您用于通过其他 SDK 显示数据的 API 很可能违反两者的条款和条件:请注意您在单个应用程序中使用的技术。 (尽管这个问题提供了使用 Bing Maps SDK 的示例代码,但我保留了上面的列表,以帮助其他可能遇到稍微不同的上下文的人。)

例如:

var manager = map.SearchManager;
var request = new ReverseGeocodeRequestOptions(location) {
    IncludeEntityTypeFlags = ReverseGeocodeEntityType.CountryRegion
};
var response = await manager.ReverseGeocodeAsync(
    new ReverseGeocodeRequestOptions(location) { );
// Use the response

如果您决定使用 Geonames API,也可以下载数据以供离线使用。

【讨论】:

  • 只是一个快速提示。将 Google API 与 Bing 地图混合使用违反了这两个平台的使用条款。使用 Bing Maps 控件时,最好坚持使用 Bing Maps API。如果这是一个需要许可证的生产应用程序,它也会使事情变得更便宜。
  • @rbrundritt:很好,我没有意识到这一点。将进行编辑以明确这一点,同时为可能不在同一条船上的其他用户维护列表。
【解决方案2】:

我创建了一个 github 项目,其中包含示例代码,无需 api 调用即可完成此操作

here

返回非常简单的国家名称和ID

【讨论】:

    猜你喜欢
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多