Как использовать службу Bing Spatial для получения близлежащих областей и как добавить их в наш элемент управления картой

Я использую запрос Api, чтобы получить близлежащие местоположения с заданным радиусом. Как добавить их в наш элемент управления картой и привязать к элементу управления пользовательского интерфейса.

 public class SpatialDataQuerying
{
   static void Main()
   {
   SpatialDataQuerying queryTest = new SpatialDataQuerying();
   queryTest.RunExampleQueries();      
   }

   public void RunExampleQueries()
   {
      ExampleFindByAreaRadius();   
   }
   public async void ExampleFindByAreaRadius()
     {
      string dataSourceName = "petrolbunk";
      string dataEntityName = "petrolbunk";

      string accessId = DataSourceID;

      string bingMapsKey = BingMapsKey;

      double SearchLatitude = 47.63674;
      double SearchLongitude =  - 122.30413;

      double Radius = 3;      
      string requestUrl = string.Format("http://spatial.virtualearth.net/REST/v1/data/{0}/{1}/{2}" + "?spatialFilter=nearby({3},{4},{5})&key={6}",accessId,dataSourceName,
    dataEntityName,SearchLatitude, SearchLongitude, Radius, bingMapsKey);

Как вы знаете, после этого запроса URL-адрес отправляется через веб-запрос HTTP.

HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse;

Теперь, как сохранить этот ответ в список и отобразить их в управлении картой. Также как привязать область к нашему элементу управления пользовательского интерфейса.


person Rognik    schedule 19.10.2015    source источник
comment
Я думаю, что ваш вопрос дублирует stackoverflow.com/questions/33212447/   -  person T N    schedule 19.10.2015


Ответы (1)


Это уже дубликат другого вопроса. Попробуйте его код и проверьте, работает ли он.

internal class NAVTEQEUDataSource : INAVTEQEUDataSource
{
public async Task<IList<Geopoint>> SearchNearBy(double latitude, double longitude, double radius, int entityTypeId, int maxResult, string bingMapKey)
{
    const string spatialBaseUrl = "http://spatial.virtualearth.net/REST/v1/data/";
    string url =
        "c2ae584bbccc4916a0acf75d1e6947b4/NavteqEU/NavteqPOIs?spatialFilter=nearby({0},{1},{2})&$filter=EntityTypeID%20eq%20'{3}'&$select=EntityID,DisplayName,Latitude,Longitude,__Distance&$top={4}&key={5}";
    HttpClient httpClient = new HttpClient { BaseAddress = new Uri(spatialBaseUrl) };
    url = string.Format(url, latitude, longitude, radius, entityTypeId, maxResult, bingMapKey);
    string response = await httpClient.GetStringAsync(url);
    XmlUtil xmlUtil = new XmlUtil(response);
    IList<XElement> properties = xmlUtil.GetElements("entry").ToList();
    IList<Geopoint> result = new List<Geopoint>();
    foreach (var property in properties)
    {
        BasicGeoposition basicGeoposition = new BasicGeoposition();

        double temp;
        if (double.TryParse(xmlUtil.GetRelativeElement(property, "content.properties.Latitude").Value, out temp))
            basicGeoposition.Latitude = temp;
        if (double.TryParse(xmlUtil.GetRelativeElement(property, "content.properties.Longitude").Value, out temp))
            basicGeoposition.Longitude = temp;
        result.Add(new Geopoint(basicGeoposition));
    }

    return result;
}
person ifaminsi    schedule 20.07.2016
comment
С некоторыми изменениями я получил вывод. Спасибо за ваш вклад - person Rognik; 20.07.2016