如何从经度和纬度中获取国家/地区名称 [英] how to get country name from latitude and longitude
问题描述
如何使用C#从纬度和经度中获取国家/地区名称? 我正在使用Bing.Map API
How can i get the country name from latitude and longtitude using c#? Im using the 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.例如:
You'll want to use a reverse geocoding API of some kind. For example:
- The Bing Maps API (the webservice)
- The Google Geocoding API
- The Geonames API
如果您已经在使用Bing.Maps SDK,则应使用Map.SearchManager
属性获取
If you're already using the Bing.Maps SDK, you should use the Map.SearchManager
property to get a SearchManager
, and then use the ReverseGeocodeAsync
method. In particular, as noted in comments, mixing and matching which API you use to show data via other SDKs may well violate the terms and conditions of both: be careful which technologies you use within a single application. (Even though this question gives sample code using the Bing Maps SDK, I've kept the list above in order to help others who may come with a slightly different context.)
例如:
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,也可以下载数据以供离线使用.
If you decide to use the Geonames API, the data can be downloaded for offline use too.
这篇关于如何从经度和纬度中获取国家/地区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!