how to get country name from latitude and longitude

☆樱花仙子☆ 提交于 2019-12-10 20:45:35

问题


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);   

回答1:


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

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.)

For example:

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

If you decide to use the Geonames API, the data can be downloaded for offline use too.




回答2:


I've created a github project with sample code that does this without api calls

see here

Very simple country name and id returned



来源:https://stackoverflow.com/questions/25866020/how-to-get-country-name-from-latitude-and-longitude

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!