如何使用 Bing 空间服务获取附近区域以及如何将它们添加到我们的地图控件中

How to use Bing Spatial service to get nearby areas and how to add them to our map control

我正在使用查询 Api 来获取给定半径内附近的位置。如何将它们添加到我们的地图控件并将它们绑定到 UI 控件。

 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 控件。

它已经是另一个问题的重复。尝试他的代码并检查它是否有效。

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