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

本文关键字:添加 控件 地图 我们 服务 空间 Bing 何使用 区域 | 更新日期: 2023-09-27 18:18:20

我使用查询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 web请求发送的。

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

现在如何将此响应存储到列表并在映射控件中显示它们。还有如何将区域绑定到UI控件。

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

这已经是另一个问题的重复了。试试他的代码,看看它是否有效。

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