开发 WinPhone SDK 开发指南 兴趣点搜索

兴趣点搜索 最后更新时间: 2021年01月22日

高德地图 Windows Phone 8 SDK 提供了四种兴趣点搜索方式,分别为:关键字、周边、区域和团购/优惠搜索。四种搜索方式有统一的入口类为AMapPOISearch,该类中提供了搜索的静态函数,您可以根据需要进行函数的选择。

关键字搜索

该查询功能根据关键字,查询该关键字所匹配的兴趣点信息,在查询时关键字和类别必选其一,同时可以选择设定城市和排序规则等,详细的参数说明参见参考手册。AMapPOISearch 中提供了两个 POIKeyWords 的重载函数,用户可以根据搜索需求进行选择,示例代码(详见demo中POISearch.xaml.cs)如下:

private async Task GetPOISearch(string city, string keywords, string types)  
{  
    //请求查询,keywords和 types必选一项进行填写  
  AMapPOIResults poirs = await AMapPOISearch.POIKeyWords(keywords, types,0, 50, 1, Extensions.All, city);  
  this.Dispatcher.BeginInvoke(() =>  //处理POI结果  
  {  
    if (poirs.Erro==null&&poirs.POIList!=null)  
    {  
      if (poirs.POIList.Count==0)  
      {  
        MessageBox.Show("无查询结果");  
        return;  
      }  
      IEnumerable poi = poirs.POIList;    //POI信息数组  
      int i = 0;  
      foreach (AMapPOI item in poi)   //遍历POI字段  
      {  
        i++;  
        Debug.WriteLine(item.Adcode);  
        Debug.WriteLine(item.Address);  
        Debug.WriteLine(item.Citycode);  
        Debug.WriteLine(item.Direction);  
        Debug.WriteLine(item.Discount_num);  
        Debug.WriteLine(item.Distance);  
        Debug.WriteLine(item.Email);  
        Debug.WriteLine(item.Entr_location);  
        Debug.WriteLine(item.Exit_location);  
        Debug.WriteLine(item.Gridcode);  
        Debug.WriteLine(item.Groupbuy_num);  
        Debug.WriteLine(item.Id);  
        Debug.WriteLine(item.Location);  
        Debug.WriteLine(item.Match);  
        Debug.WriteLine(item.Name);  
        Debug.WriteLine(item.Navi_poiid);  
        Debug.WriteLine(item.Postcode);  
        Debug.WriteLine(item.Recommend);  
        Debug.WriteLine(item.Rich_content);  
        Debug.WriteLine(item.Tel);  
        Debug.WriteLine(item.Timestamp);  
        Debug.WriteLine(item.Type);  
        Debug.WriteLine(item.Website);  
        Debug.WriteLine(item.Weight);  
        amap.AddMarker(new AMapMarkerOptions()   //将POI作为标注显示到地图上  
        {  
          Position = new LatLng(item.Location.Lat, item.Location.Lon),  
          Title = "Title",  
          Snippet = "Snippet",  
          IconUri = new Uri("Images/marker_gps_no_sharing.png", UriKind.Relative),  
        });  
      }  
      Debug.WriteLine(i);  
    }  
    else{  
      MessageBox.Show(poirs.Erro.Message);  
    }  
  });  
}  

周边搜索

该查询可以实现以某一地理坐标点为圆心,指定半径和指定关键字附近的兴趣点信息,在查询时关键字和类别必选其一,中心点坐标为必选项,同时可以设定查询半径、城市和排序规则等,详细的参数说明参见参考手册。AMapPOISearch 中提供了三个 POIAround 的重载函数, 用户可以根据搜索需求进行选择,示例代码(详见demo中POIAround.xaml.cs)如下:

  
private async void GetPOIAround(double centerX, double centerY, string keywords, string types, uint radius, string city)  
{  
  AMapPOIResults poir = await AMapPOISearch.POIAround(centerX, centerY,true,true, keywords, types, radius, 0, 50, 1, Extensions.All, city);  
  this.Dispatcher.BeginInvoke(() =>  
  {  
    if (poir.Erro == null && poir.POIList != null)  
    {  
      if (poir.POIList.Count == 0)  
      {  
        MessageBox.Show("无查询结果");  
        return;  
      }  
      IEnumerablee pois = poir.POIList;  
      int i = 0;  
      foreach (AMapPOI item in pois)  
      {  
        i++;  
        Debug.WriteLine(item.Adcode);  
        Debug.WriteLine(item.Address);   
        Debug.WriteLine(item.Citycode);  
        Debug.WriteLine(item.Direction);  
        Debug.WriteLine(item.Discount_num);  
        Debug.WriteLine(item.Distance);   
        Debug.WriteLine(item.Email);  
        Debug.WriteLine(item.Entr_location);  
        Debug.WriteLine(item.Exit_location);  
        Debug.WriteLine(item.Gridcode);  
        Debug.WriteLine(item.Groupbuy_num);  
        Debug.WriteLine(item.Id);  
        Debug.WriteLine(item.Location);  
        Debug.WriteLine(item.Match);  
        Debug.WriteLine(item.Name);  
        Debug.WriteLine(item.Navi_poiid);  
        Debug.WriteLine(item.Postcode);  
        Debug.WriteLine(item.Recommend);  
        Debug.WriteLine(item.Rich_content);  
        Debug.WriteLine(item.Tel);  
        Debug.WriteLine(item.Timestamp);  
        Debug.WriteLine(item.Type);  
        Debug.WriteLine(item.Website);  
        Debug.WriteLine(item.Weight);  
        amap.AddMarker(new AMapMarkerOptions()  
        {  
          Position = new LatLng(item.Location.Lat, item.Location.Lon),//amap.Center,//  
          Title = "Title",  
          Snippet = "Snippet",  
          IconUri = new Uri("Images/marker_gps_no_sharing.png", UriKind.Relative),  
        });  
      }  
      Debug.WriteLine(i);  
    }  
    else  
    {  
      MessageBox.Show(poir.Erro.Message);  
    }  
  });  
} 
 

指定区域搜索

可以实现查询某一多边形范围内,指定关键字附近的兴趣点信息,在查询时关键字和类别必选其一,多边形为必选项,同时可以设定城市和排序规则等,详细的参数说明参见参考手册。AMapPOISearch 中提供了三个 POIPolygon 的重载函数, 用户可以根据搜索需求进行选择,示例代码(详见demo中POIPolygonSearch.xaml.cs)如下:

private async void GetPOIPolygonSearch(string keywords, string types, string city, uint offset)  
{  
  //构建搜索多边形  
  AMapPolygon polygon = new AMapPolygon();  
  polygon._Type = AMapPolygon.Types.Type.POLYGON;  
  polygon.Points = new List();  
  polygon.Points.Add(new Location() { Lon = 116.460988, Lat = 40.006919 });  
  polygon.Points.Add(new Location() { Lon = 116.48231, Lat = 40.007381 });  
  polygon.Points.Add(new Location() { Lon = 116.47516, Lat = 39.99713 });  
  polygon.Points.Add(new Location() { Lon = 116.472596, Lat = 39.985227 });  
  polygon.Points.Add(new Location() { Lon = 116.45669, Lat = 39.984989 });  
  polygon.Points.Add(new Location() { Lon = 116.460988, Lat = 40.006919 });  
  //请求查询,keywords和 types必选一项进行填写  
  AMapPOIResults poir =await AMapPOISearch.POIPolygon(keywords, types, polygon,0,  offset, 1, Extensions.All, city);  
  this.Dispatcher.BeginInvoke(() =>    //处理结果  
  {  
    if (poir.Erro == null && poir.POIList != null)  
    {  
      if (poir.POIList.Count==0)  
      {  
        MessageBox.Show("无查询结果");  
        return;  
      }  
      IEnumerablee pois = poir.POIList;   //POI信息数组  
      int i = 0;  
      foreach (AMapPOI item in pois)  //遍历POI字段  
      {  
        i++;  
        Debug.WriteLine(item.Adcode);  
        Debug.WriteLine(item.Address);   
        Debug.WriteLine(item.Citycode);  
        Debug.WriteLine(item.Direction);  
        Debug.WriteLine(item.Discount_num);  
        Debug.WriteLine(item.Distance);   
        Debug.WriteLine(item.Email);  
        Debug.WriteLine(item.Entr_location);  
        Debug.WriteLine(item.Exit_location);  
        Debug.WriteLine(item.Gridcode);  
        Debug.WriteLine(item.Groupbuy_num);  
        Debug.WriteLine(item.Id);  
        Debug.WriteLine(item.Location);  
        Debug.WriteLine(item.Match);  
        Debug.WriteLine(item.Name);  
        Debug.WriteLine(item.Navi_poiid);  
        Debug.WriteLine(item.Postcode);  
        Debug.WriteLine(item.Recommend);  
        Debug.WriteLine(item.Rich_content);  
        Debug.WriteLine(item.Tel);  
        Debug.WriteLine(item.Timestamp);  
        Debug.WriteLine(item.Type);  
        Debug.WriteLine(item.Website);  
        Debug.WriteLine(item.Weight);  
        amap.AddMarker(new AMapMarkerOptions()   //将POI作为标注显示到地图上  
        {  
          Position = new LatLng(item.Location.Lat, item.Location.Lon),//amap.Center,//  
          Title = "Title",  
          Snippet = "Snippet",  
          IconUri = new Uri("Images/marker_gps_no_sharing.png", UriKind.Relative),  
        });  
      }  
      Debug.WriteLine(i);  
    }  
    else  
    {  
      MessageBox.Show(poir.Erro.Message);  
    }  
  });  
}  

团购/优惠搜索

可以根据某一兴趣点ID查询该兴趣点的基础信息和深度信息(团购和优惠),id为必选项,详细的参数说明参见参考手册。AMapPOISearch 中提供了 POIID 函数查询深度信息,示例代码(详见demo中POIIDSearch.xaml.cs)如下:

private async void GetPOIID(string id)  
{  
  //请求查询,id为必填项  
  AMapPOIResults poir = await AMapPOISearch.POIID(id);  
  this.Dispatcher.BeginInvoke(() =>   //处理结果  
  {  
    if (poir.Erro==null&&poir.POIList!=null)  
    {  
      if (poir.POIList.Count==0)  
      {  
        MessageBox.Show("无查询结果");  
        return;  
      }  
      int i = 0;  
      foreach (AMapPOI item in poir.POIList)   //遍历POI字段  
      {  
        i++;  
        Debug.WriteLine(item.Adcode);  
        Debug.WriteLine(item.Address);   
        Debug.WriteLine(item.Citycode);  
        Debug.WriteLine(item.Direction);  
        Debug.WriteLine(item.Discount_num);  
        Debug.WriteLine(item.Distance);   
        Debug.WriteLine(item.Email);  
        Debug.WriteLine(item.Entr_location);  
        Debug.WriteLine(item.Exit_location);  
        Debug.WriteLine(item.Gridcode);  
        Debug.WriteLine(item.Groupbuy_num);  
        Debug.WriteLine(item.Id);  
        Debug.WriteLine(item.Location);  
        Debug.WriteLine(item.Match);  
        Debug.WriteLine(item.Name);  
        Debug.WriteLine(item.Navi_poiid);  
        Debug.WriteLine(item.Postcode);  
        Debug.WriteLine(item.Recommend);  
        Debug.WriteLine(item.Rich_content);  
        Debug.WriteLine(item.Tel);  
        Debug.WriteLine(item.Timestamp);  
        Debug.WriteLine(item.Type);  
        Debug.WriteLine(item.Website);  
        Debug.WriteLine(item.Weight);  
        amap.AddMarker(new AMapMarkerOptions()   //将POI作为标注显示到地图上  
        {  
          Position = new LatLng(item.Location.Lat, item.Location.Lon),//amap.Center,//  
          Title = "Title",  
          Snippet = "Snippet",  
          IconUri = new Uri("Images/marker_gps_no_sharing.png", UriKind.Relative),  
        });  
      }  
      Debug.WriteLine(i);  
    }  
    else  
    {  
      MessageBox.Show(poir.Erro.Message);  
    }  
  });  
 }       
返回顶部 示例中心 常见问题 智能客服 公众号
二维码