如何使用 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。例如:
- The 必应地图 API http://msdn.microsoft.com/en-GB/library/ff701710.aspx(网络服务)
- The 谷歌地理编码API https://developers.google.com/maps/documentation/geocoding/
- The 地名API http://www.geonames.org/export/web-services.html
如果您已经在使用 Bing.Maps SDK,则应该使用Map.SearchManager
属性以获得SearchManager http://msdn.microsoft.com/en-us/library/dn306041.aspx,然后使用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,也可以下载数据以供离线使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)