热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【高德地图API】地理编码与逆地理编码

一、地理编码该功能实现地理编码服务,即地址匹配,从已知的地址描述到对应的经纬度坐标的转换,即根据地址信息,查询该地址所对应的点坐标等,地址(address)为必选项,城市(ci

一、地理编码

该功能实现地理编码服务,即地址匹配,从已知的地址描述到对应的经纬度坐标的转换,即根据地址信息,查询该地址所对应的点坐标等,地址(address)
为必选项,城市(city)为可选项。


bubuko.com,布布扣id="code_img_closed_ed5b62e0-c864-4866-9eb5-0ead95d6c81d" class="code_img_closed"
src="https://img.php1.cn/3cd4a/1eebe/cd5/7d7ef3f69d479716.webp">bubuko.com,布布扣 id="code_img_opened_ed5b62e0-c864-4866-9eb5-0ead95d6c81d"
class="code_img_opened" Onclick="cnblogs_code_hide(‘ed5b62e0-c864-4866-9eb5-0ead95d6c81d‘,event)"
src="https://img.php1.cn/3cd4a/1eebe/cd5/8ad8f3bf8da691df.webp">

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid Opacity="0.8" Margin="0,0,0,608" Background="#FF323232" RenderTransformOrigin="0.497,0.465" Canvas.ZIndex="10" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="地理编码" Margin="3,0,0,0" />
<StackPanel Grid.Row="1" Orientation="Vertical">
<TextBox x:Name="txtAddress" Grid.Row="0" Text="北京市朝阳区望京阜通东大街方恒国际中心" Margin="12,0,0,0" />
<Button Content="地理编码" Click="Button_Click" Margin="274,0,26,0" />
StackPanel>
Grid>
Grid>

View Code

 



AMap amap;
AMapMarker marker;
public SearchGeoCode()
{
InitializeComponent();
this.ContentPanel.Children.Add(amap = new AMap());
amap.MarkerClickListener
+= amap_MarkerClickListener;

}
private async Task AddressToGeoCode(string address)
{
AMapGeoCodeResult cr
= await AMapGeoCodeSearch.AddressToGeoCode(address);
this.Dispatcher.BeginInvoke(() =>
{
if (cr.Erro == null && cr.GeoCodeList != null)
{
if (cr.GeoCodeList.Count==0)
{
MessageBox.Show(
"无查询结果");
return;
}
IEnumerable
geocode = cr.GeoCodeList;
foreach (AMapGeoCode gcs in geocode)
{
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),
Title
= gcs.FormattedAddress,
Snippet
= gcs.District,
IconUri
= new Uri("Images/AZURE.png", UriKind.Relative),
});
}
//如果返回的geocode数大于1个,调整视图
if (geocode.Count()>1)
{
LatLngBounds.Builder builder
= new LatLngBounds.Builder();
List
markers = amap.GetMapMarkers();
foreach (AMapMarker marker in markers)
{
builder.Include(marker.Position);
}
this.amap.MoveCamera(CameraUpdateFactory.NewLatLngBounds(builder.Build(), markers.Count()));
}
else
{
amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(
new LatLng(geocode.FirstOrDefault().Location.Lat, geocode.FirstOrDefault().Location.Lon), 14));
}
}
else
{
MessageBox.Show(cr.Erro.Message);
}
});
}
void amap_MarkerClickListener(AMapMarker sender, AMapEventArgs args)
{
sender.ShowInfoWindow(
new AInfoWindow()
{
Title
= sender.Title,
ContentText
=sender.Snippet,
});
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
amap.Clear();
if (!string.IsNullOrWhiteSpace(txtAddress.Text))
{
await AddressToGeoCode(txtAddress.Text);
}

}


二、逆地理编码

该功能实现逆地理编码服务,即地址解析服务,具体是指从已知的经纬度坐标到对应的地址描述(如省市、街区、楼层、房间等)的转换服务,坐标(location)
为必选项,半径(radius)为可选项,详细的参数说明参见参考手册。

 


bubuko.com,布布扣id="code_img_closed_14184656-7c7e-45f7-8d80-db9a01cce6b1" class="code_img_closed"
src="https://img.php1.cn/3cd4a/1eebe/cd5/7d7ef3f69d479716.webp">bubuko.com,布布扣 id="code_img_opened_14184656-7c7e-45f7-8d80-db9a01cce6b1"
class="code_img_opened" Onclick="cnblogs_code_hide(‘14184656-7c7e-45f7-8d80-db9a01cce6b1‘,event)"
src="https://img.php1.cn/3cd4a/1eebe/cd5/8ad8f3bf8da691df.webp">

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid Opacity="0.8" Margin="0,0,0,568" Background="#FF323232" RenderTransformOrigin="0.497,0.465" Canvas.ZIndex="10" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="逆地理编码" Margin="3,0,0,0" />

<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="经度:" Margin="12,0,0,0" VerticalAlignment="Center" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="纬度:" Margin="12,0,0,0" VerticalAlignment="Center" />
<TextBox x:Name="txtLon" Grid.Row="0" Grid.Column="1" Text="" Width="180" />
<TextBox x:Name="txtLat" Grid.Row="1" Grid.Column="1" Text="" Width="180" />
<TextBlock Grid.Row="2" Text="点击或者输入获得经纬度" Grid.ColumnSpan="2" Margin="3,0,0,0" />
Grid>
<Button Content="逆地理编码" Click="Button_Click" Margin="257,69,29,3" Grid.Row="1" />

Grid>


View Code

 



AMap amap;
AMapMarker marker;
LatLng latLng;
public SearchReGeoCode()
{
InitializeComponent();
this.ContentPanel.Children.Add(amap = new AMap());
amap.Tap
+= amap_Tap;
amap.MarkerClickListener
+= amap_MarkerClickListener;
}
void amap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
latLng
= amap.GetProjection().FromScreenLocation(e.GetPosition(amap));
this.txtLat.Text = latLng.latitude.ToString();
this.txtLon.Text = latLng.longitude.ToString();
}
private async Task GeoCodeToAddress(double lon, double lat)
{
AMapReGeoCodeResult rcc
= await AMapReGeoCodeSearch.GeoCodeToAddress(lon, lat, 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();
//POI信息点
foreach (AMapPOI poi in pois)
{
marker
= amap.AddMarker(new AMapMarkerOptions()
{
Position
= new LatLng(poi.Location.Lat, poi.Location.Lon),
Title
= poi.Name,
Snippet
= poi.Address,
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(streetNumber.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 LatLng(streetNumber.Location.Lat, streetNumber.Location.Lon),//amap.Center,//
Title = addressComponent.Province,
Snippet
= regeocode.Formatted_address,
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));
amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(
new LatLng(Convert.ToDouble(txtLon.Text), Convert.ToDouble(txtLat.Text)), 12));
}
else
{
MessageBox.Show(rcc.Erro.Message);
}
});
}
void amap_MarkerClickListener(AMapMarker sender, AMapEventArgs args)
{
sender.ShowInfoWindow(
new AInfoWindow()
{
Title
= sender.Title,
ContentText
= sender.Snippet,
});
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
amap.Clear();
if (string.IsNullOrWhiteSpace(txtLat.Text) && string.IsNullOrWhiteSpace(txtLon.Text))
{
return;
}
await GeoCodeToAddress(Convert.ToDouble(txtLon.Text), Convert.ToDouble(txtLat.Text));
}

 


三、同时使用地理编码和逆地理编码

已知一个地址或者模糊地址,然后你想知道该地址详细信息或者周边信息(周边POI点)。先通过地址获取经纬度,然后通过逆地理编码获取详细信息。在此不作出示例。


四、批量逆地理编码

目前高德地图WP SDK中并没有提供>直接批量转换的接口,而在REST
API中已经提供了,你可以在开发者论坛REST API版块中提出接口使用申请,链接:高德地图rest
api接口申请方式
 


推荐阅读
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 在project.properties添加#Projecttarget.targetandroid-19android.library.reference.1..Sliding ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了指针的概念以及在函数调用时使用指针作为参数的情况。指针存放的是变量的地址,通过指针可以修改指针所指的变量的值。然而,如果想要修改指针的指向,就需要使用指针的引用。文章还通过一个简单的示例代码解释了指针的引用的使用方法,并思考了在修改指针的指向后,取指针的输出结果。 ... [详细]
author-avatar
七楼居民_651
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有