开发 WinPhone SDK 开发指南 坐标/地址查询

坐标/地址查询 最后更新时间: 2021年01月22日

地理编码

该功能实现地理编码服务,即地址匹配,从已知的地址描述到对应的经纬度坐标的转换,即根据地址信息,查询该地址所对应的点坐标等,地址(address) 为必选项,城市(city)为可选项。AMapGeoCodeSearc h中提供了两个 AddressToGeoCode 的重载函数,示例代码(详见demo中SearchGeoCode.xaml.cs)如下:

private async Task AddressToGeoCode()  
{  
  //请求查询,地址(address) 为必选项  
  AMapGeoCodeResult cr = await AMapGeoCodeSearch.AddressToGeoCode("北京市朝阳区望京阜通东大街方恒国际中心", "北京");  
  this.Dispatcher.BeginInvoke(() =>   //处理结果  
  {  
    if (cr.Erro == null && cr.GeoCodeList != null)  
    {  
      if (cr.GeoCodeList.Count==0)  
      {  
        MessageBox.Show("无查询结果");  
        return;  
      }  
      IEnumerable geocode = cr.GeoCodeList;  
      int i = 0;  
      foreach (AMapGeoCode gcs in geocode)  
      {  
        i++;  
        Debug.WriteLine(gcs.Adcode);  
        Debug.WriteLine(gcs.Building);  
        Debug.WriteLine(gcs.City);  
        Debug.WriteLine(gcs.District);  
        Debug.WriteLine(gcs.FormattedAddress);  
        Debug.WriteLine(gcs.Province);  
        Debug.WriteLine(gcs.Township);  
        Debug.WriteLine(gcs.Location.Lon);  
        Debug.WriteLine(gcs.Location.Lat);  
        Debug.WriteLine(gcs.LevelList[0]);  
        marker= amap.AddMarker(new AMapMarkerOptions()  
        {  
          Position = new LatLng(gcs.Location.Lat, gcs.Location.Lon),//amap.Center,//  
          Title = "Title",  
          Snippet = "Snippet",  
          IconUri = new Uri("Images/AZURE.png", UriKind.Relative),  
        });  
        marker.ShowInfoWindow(new AInfoWindow()  
        {  
          Title = gcs.District,  
          ContentText = gcs.District,  
        });  
      }  
      Debug.WriteLine(i);  
    }  
    else  
    {  
      MessageBox.Show(cr.Erro.Message);  
    }  
  });  
}   

逆地理编码

该功能实现逆地理编码服务,即地址解析服务,具体是指从已知的经纬度坐标到对应的地址描述(如省市、街区、楼层、房间等)的转换服务,坐标(location) 为必选项,半径(radius)为可选项,详细的参数说明参见参考手册。AMapReGeoCodeSearch 中提供了两个 GeoCodeToAddress 的重载函数,示例代码(详见demo中SearchReGeoCode.xaml.cs)如下:

private async Task GeoCodeToAddress()  
{  
  //请求查询  
  AMapReGeoCodeResult rcc = await AMapReGeoCodeSearch.GeoCodeToAddress(Convert.ToDouble(txtLat.Text),Convert.ToDouble(txtLon.Text),500,"",Extensions.All);  
  this.Dispatcher.BeginInvoke(() =>   //处理结果  
  {  
    if (rcc.Erro == null && rcc.ReGeoCode != null)  
    {  
      AMapReGeoCode regeocode = rcc.ReGeoCode;  
      Debug.WriteLine(regeocode.Address_component);  
      Debug.WriteLine(regeocode.Formatted_address);  
      Debug.WriteLine(regeocode.Pois);  
      List pois = regeocode.Pois.ToList();  
      foreach (AMapPOI poi in pois)  
      {  
        marker = amap.AddMarker(new AMapMarkerOptions()  
        {  
          Position = new LatLng(poi.Location.Lat, poi.Location.Lon),  
          Title = "Title",  
          Snippet = "Snippet",  
          IconUri = new Uri("Images/RED.png", UriKind.Relative),  
        });  
      }  
      Debug.WriteLine(regeocode.Roadinters);  
      Debug.WriteLine(regeocode.Roadslist);  
      AMapAddressComponent addressComponent = regeocode.Address_component;  
      Debug.WriteLine(addressComponent.Building);  
      Debug.WriteLine(addressComponent.City);  
      Debug.WriteLine(addressComponent.District);  
      Debug.WriteLine(addressComponent.Neighborhood);  
      Debug.WriteLine(addressComponent.Province);  
      Debug.WriteLine(addressComponent.Stree_number);  
      Debug.WriteLine(addressComponent.Township);  
      AMapStreetNumber streetNumber = addressComponent.Stree_number;  
      Debug.WriteLine(streetNumber.Direction);  
      Debug.WriteLine(street N mber.Distance);  
      Debug.WriteLine(streetNumber.Location.Lat);  
      Debug.WriteLine(streetNumber.Location.Lon);  
      Debug.WriteLine(streetNumber.Number);  
      Debug.WriteLine(streetNumber.Street);  
      marker = amap.AddMarker(new AMapMarkerOptions()  
      {  
        Position = new LatLngConvert.ToDouble(txtLat.Text),Convert.ToDouble(txtLon.Text)),  
        Title = "Title",  
        Snippet = "Snippet",  
        IconUri = new Uri("Images/AZURE.png", UriKind.Relative),  
      });  
      //显示化弹出信息  
      AInfoWindow info = new AInfoWindow();  
      info.Title = addressComponent.Province;  
      info.ContentText = regeocode.Formatted_address;  
      marker.ShowInfoWindow(info, new Point(0, 0));  
    }  
    else  
    {  
      MessageBox.Show(rcc.Erro.Message);  
    }  
  });  
}   
返回顶部 示例中心 常见问题 智能客服 公众号
二维码