如何从纬度和经度获取国家/地区名称

如何使用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); 

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

  • Bing Maps API (网络服务)
  • Google地理编码API
  • Geonames API

如果您已经在使用Bing.Maps SDK,则应使用Map.SearchManager属性获取SearchManager ,然后使用ReverseGeocodeAsync方法。 特别是,如评论中所述,混合和匹配您用于通过其他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,则可以下载数据以供离线使用。

我已经创建了一个带有示例代码的github项目,无需api调用即可完成此操作

看到这里

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