Как да използваме услугата 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;

Сега как да съхраните този отговор в списък и да ги покажете в контрола на картата. Също така как да обвържем зоната с нашия UI контрол.


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