【Android】3.11 地理编码功能
分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04
一、简介
地理编码指的是将地址信息建立空间坐标关系的过程,提供了地理坐标和地址之间相互转换的能力。
地理编码分为正向地图编码和反向地图编码。
l 正向地理编码:将中文地址或地名描述转换为地球表面上相应位置;
l 反向地理编码:将地球表面的地址坐标转换为标准地址的过程。
1、正向地理编码
正向地理编码指的是由地址信息转换为坐标点的过程。
2、反向地理编码
反向地理编码服务实现了将地球表面的地址坐标转换为标准地址的过程。
反向地理编码提供了坐标定位引擎,帮助用户通过地面某个地物的坐标值来反向查询得到该地物所在的行政区划、所处街道、以及最匹配的标准地址信息。通过丰富的标准地址库中的数据,可帮助用户在进行移动端查询、商业分析、规划分析等领域创造无限价值。
反向地理编码的实现形式与正向地理编码的方式相同,此处不再赘述。(更多详细信息请参考Demo中的代码)
二、运行截图
简介:介绍地址信息与坐标之间的相互转换
详述:
(1)正向地理编码:将地址信息转换为经纬度坐标;
(2)反向地理编码:将经纬度坐标转换为地址信息;
本示例运行截图如下:
三、设计步骤
1、添加demo11_geocoder.xml文件
在layout文件夹下添加该文件,然后将代码改为下面的内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <EditText
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="北京" /> <EditText
android:id="@+id/geocodekey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="海淀区上地十街10号" /> <Button
android:id="@+id/geocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_style"
android:text="Geo" />
</LinearLayout> <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <EditText
android:id="@+id/lat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="39.904965" /> <EditText
android:id="@+id/lon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="116.327764" /> <Button
android:id="@+id/reversegeocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_style"
android:text="ReverseGeo" />
</LinearLayout> <com.baidu.mapapi.map.TextureMapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" /> </LinearLayout>
2、添加Demo11GeoCoder.cs文件
在SrcSdkDemos文件夹下添加该文件,然后将代码改为下面的内容:
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Widget;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Model;
using Com.Baidu.Mapapi.Search.Core;
using Com.Baidu.Mapapi.Search.Geocode; namespace BdMapV371Demos.SrcSdkDemos
{
/// <summary>
/// 此demo用来展示如何进行地理编码搜索(用地址检索坐标)、反地理编码搜索(用坐标检索地址)
/// </summary>
[Activity(Label = "@string/demo_name_geocode",
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
ScreenOrientation = ScreenOrientation.Sensor)]
public class Demo11GeoCoder : Activity
{
GeoCoder mSearch = null; // 搜索模块,也可去掉地图模块独立使用
BaiduMap mBaiduMap = null;
TextureMapView mMapView = null; protected override void OnCreate(Bundle savedInstanceState)
{ base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.demo11_geocoder); // 地图初始化
mMapView = FindViewById<TextureMapView>(Resource.Id.bmapView);
mBaiduMap = mMapView.Map; var btnGeocode = FindViewById<Button>(Resource.Id.geocode);
btnGeocode.Click += (s, e) =>
{
EditText editCity = FindViewById<EditText>(Resource.Id.city);
EditText editGeoCodeKey = FindViewById<EditText>(Resource.Id.geocodekey);
// Geo搜索
mSearch.Geocode(new GeoCodeOption()
.City(editCity.Text)
.Address(editGeoCodeKey.Text));
}; var btnReverseGeocode = FindViewById<Button>(Resource.Id.reversegeocode);
btnReverseGeocode.Click += (s, e) =>
{
EditText lat = FindViewById<EditText>(Resource.Id.lat);
EditText lon = FindViewById<EditText>(Resource.Id.lon);
LatLng ptCenter = new LatLng(float.Parse(lat.Text), float.Parse(lon.Text));
// 反Geo搜索
mSearch.ReverseGeoCode(new ReverseGeoCodeOption()
.Location(ptCenter));
}; // 初始化搜索模块,注册搜索结果事件
mSearch = GeoCoder.NewInstance();
mSearch.GetGeoCodeResult += (s, e) =>
{
var result = e.P0;
if (result == null || result.Error != SearchResult.ERRORNO.NoError)
{
Toast.MakeText(this, "抱歉,未能找到结果", ToastLength.Long).Show();
}
mBaiduMap.Clear();
mBaiduMap.AddOverlay(new MarkerOptions()
.InvokePosition(result.Location)
.InvokeIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_marka)));
mBaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(result.Location));
string info = string.Format("纬度:{0:f6},经度:{1:f6}",
result.Location.Latitude, result.Location.Longitude);
Toast.MakeText(this, info, ToastLength.Long).Show();
};
mSearch.GetReverseGeoCodeResult += (s, e) =>
{
var result = e.P0;
if (result == null || result.Error != SearchResult.ERRORNO.NoError)
{
Toast.MakeText(this, "抱歉,未能找到结果", ToastLength.Long).Show();
}
mBaiduMap.Clear();
mBaiduMap.AddOverlay(new MarkerOptions()
.InvokePosition(result.Location)
.InvokeIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_markb)));
mBaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(result.Location));
Toast.MakeText(this, result.Address, ToastLength.Long).Show();
};
} protected override void OnPause()
{
mMapView.OnPause();
base.OnPause();
} protected override void OnResume()
{
mMapView.OnResume();
base.OnResume();
} protected override void OnDestroy()
{
mMapView.OnDestroy();
mSearch.Destroy();
base.OnDestroy();
}
}
}
3、修改MainActivity.cs
在MainActivity.cs文件的demos字段定义中,去掉【示例11】下面的注释。
运行观察结果。
【Android】3.11 地理编码功能的更多相关文章
- 我的Android进阶之旅------>Android百度地图定位SDK功能学习
因为项目需求,需要使用百度地图的定位功能,因此去百度地图开发平台下载了百度地图的Android定位SDK最新版本的开发包和示例代码学习. Android 定位SDK地址:http://develope ...
- (转载) 百度地图工具类封装(包括定位,附近、城市、范围poi检索,反地理编码)
目录视图 摘要视图 订阅 赠书 | 异步2周年,技术图书免费选 程序员8月书讯 项目管理+代码托管+文档协作,开发更流畅 百度地图工具类封装(包括定位,附近.城市.范围poi检索, ...
- iOS 原生地图地理编码与反地理编码
当我们要在App实现功能:输入地名,编码为经纬度,实现导航功能. 那么,我需要用到原生地图中的地理编码功能,而在Core Location中主要包含了定位.地理编码(包括反编码)功能. 在文件中导入 ...
- Android百度地图开发02之添加覆盖物 + 地理编码和反地理编码
下面来看一下地图上覆盖物的添加,以及地理编码和反地理编码. 添加覆盖物 在地图上添加覆盖物,一般需要以下几个步骤: 1. 定义坐标点,有可能是一个,有可能是多个(比如:多边形覆盖物). 2. 构造Ov ...
- 【iOS】7.4 定位服务->2.1.3.2 定位 - 官方框架CoreLocation 功能2:地理编码和反地理编码
本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...
- android studio高德地图的显示于定位(附带逆地理编码围栏)
首先注册高德成为开发者(打开高德地图,点击底部的开发者平台),创建应用,按照要求填写相应信息 网站:http://lbs.amap.com/api/android-sdk/guide/create-p ...
- 高德地图添加marker及反地理编码获取POI
项目中集成百度.高德.腾讯地图已是司空见惯的事情,今天我总结了一下项目中用到的高德地图常用的功能: 1.展示高德地图并定位显示定位图标: 2.添加实时大头针: 3.反地理编码获取周围兴趣点 效果如下: ...
- IOS高德地图逆地理编码定位+网络判断
先说下这功能的流程, 流程:判断用户是否联网--->获取用户地理位置经纬度--->通过经纬度去查询地理位置名称 //高德地图 @property (nonatomic, strong) ...
- CoreLocation框架的使用---地理编码
#import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...
随机推荐
- 解决m2e插件maven-dependency-plugin问题
http://blog.csdn.net/smst1987/article/details/6871495 问题:maven-dependency-plugin (goals "copy-d ...
- C++使用hiredis连接带密码的redis服务
c = redisConnect((char*)redis_host, redis_port); if (c->err) { /* Error flags, 0 when there is no ...
- Android自动填写获取到的验证码
Android需要添加的相关权限 <uses-permission android:name="android.permission.RECEIVE_SMS">< ...
- spring task:annotation-driven 定时任务
1.配置文件加上<task:annotation-driven/> 2.要运行的方法前加上 @Scheduled(cron="0 00 12 1 * ?") //每月 ...
- 〖Linux〗联想K860/i Android 4.2及以上的Bootimg解压与打包工具
因为自己有需要,所以花了一点时间来写了一下. 1. 解压工具 #!/bin/bash - #====================================================== ...
- API密钥
什么是API密钥? 答:在api调用时,用来按照指定规则对您的请求参数进行签名,服务器收到你的请求时会进行签名验证,即可以界定你的身份也可以防止其他人通过某种手段恶意篡改你的请求数据. 密钥的使用? ...
- 如何在Eclipse中查看JDK以及Java框架的源码
方法一:快速简单 第一步: 打开你的Eclipse,然后随便找一个Java文件,随便找一个Java类库,比如String什么的,然后按住Ctrl,再点击它,你会发现跳到如下界面: 你会发现报错了:So ...
- Zuul使用Ribbon配置自动重试
spring cloud的版本不断演进,导致很多配置的配置方式不断改变,有时某个配置在一个版本里面默认是true,后边一升级默认成了false,这点让人有点不爽. 言归正传 0.所使用版本 sprin ...
- Eclipse调试cas server 3.5.2.1
由于在配置CAS+LDAP总是报错,决定Eclipse调试cas server,跟踪问题出在哪里? ================================================== ...
- Java中将InputStream读取为String, 各种方法的性能对比
如下, 一共存在11种实现方式及其对应的性能测试结果: 1. 使用IOUtils.toString (Apache Utils) String result = IOUtils.toString(in ...