分类: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 地理编码功能的更多相关文章

  1. 我的Android进阶之旅------>Android百度地图定位SDK功能学习

    因为项目需求,需要使用百度地图的定位功能,因此去百度地图开发平台下载了百度地图的Android定位SDK最新版本的开发包和示例代码学习. Android 定位SDK地址:http://develope ...

  2. (转载) 百度地图工具类封装(包括定位,附近、城市、范围poi检索,反地理编码)

    目录视图 摘要视图 订阅 赠书 | 异步2周年,技术图书免费选      程序员8月书讯      项目管理+代码托管+文档协作,开发更流畅 百度地图工具类封装(包括定位,附近.城市.范围poi检索, ...

  3. iOS 原生地图地理编码与反地理编码

    当我们要在App实现功能:输入地名,编码为经纬度,实现导航功能. 那么,我需要用到原生地图中的地理编码功能,而在Core Location中主要包含了定位.地理编码(包括反编码)功能. 在文件中导入 ...

  4. Android百度地图开发02之添加覆盖物 + 地理编码和反地理编码

    下面来看一下地图上覆盖物的添加,以及地理编码和反地理编码. 添加覆盖物 在地图上添加覆盖物,一般需要以下几个步骤: 1. 定义坐标点,有可能是一个,有可能是多个(比如:多边形覆盖物). 2. 构造Ov ...

  5. 【iOS】7.4 定位服务->2.1.3.2 定位 - 官方框架CoreLocation 功能2:地理编码和反地理编码

    本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...

  6. android studio高德地图的显示于定位(附带逆地理编码围栏)

    首先注册高德成为开发者(打开高德地图,点击底部的开发者平台),创建应用,按照要求填写相应信息 网站:http://lbs.amap.com/api/android-sdk/guide/create-p ...

  7. 高德地图添加marker及反地理编码获取POI

    项目中集成百度.高德.腾讯地图已是司空见惯的事情,今天我总结了一下项目中用到的高德地图常用的功能: 1.展示高德地图并定位显示定位图标: 2.添加实时大头针: 3.反地理编码获取周围兴趣点 效果如下: ...

  8. IOS高德地图逆地理编码定位+网络判断

    先说下这功能的流程,  流程:判断用户是否联网--->获取用户地理位置经纬度--->通过经纬度去查询地理位置名称 //高德地图 @property (nonatomic, strong) ...

  9. CoreLocation框架的使用---地理编码

    #import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...

随机推荐

  1. ImportError: No module named arcpy

    好久没写Python脚本了,今天一运行就报错:未找到名称为 arcpy 的模块(ImportError: No module named arcpy). 多半是环境变量出问题了,Python最令人讨厌 ...

  2. android studio中使用adb wifi插件无线调试程序

    使用android studio中使用adb wifi插件无线调试程序的前提条件电脑和手机在同一个无线网 1.下载adb wifi插件 File->Settings->Plugins Br ...

  3. strcpy sprintf memcpy 它们之间的区别

    strcpy,sprintf,memcpy的区别 strcpy 函数操作的对象是 字符串,完成 从 源字符串 到 目的字符串 的 拷贝 功能.  snprintf 函数操作的对象 不限于字符串:虽然目 ...

  4. 算法笔记_177:历届试题 城市建设(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 栋栋居住在一个繁华的C市中,然而,这个城市的道路大都年久失修.市长准备重新修一些路以方便市民,于是找到了栋栋,希望栋栋能帮助他. C市中有 ...

  5. YUM常用命令详解

    yum是一个用于管理rpm包的后台程序,用python写成,可以非常方便的解决rpm的依赖关系.在建立好yum服务器后,yum客户端可以通过 http.ftp方式获得软件包,并使用方便的命令直接管理. ...

  6. Exif介绍

    Exif是一种图像文件格式,它的数据存储与JPEG格式是完全相同的.实际上Exif格式就是在JPEG格式头部插入了数码照片的信息,包括拍摄时的光圈.快门.白平衡.ISO.焦距.日期时间等各种和拍摄条件 ...

  7. org.dom4j.DocumentException:对实体 "virtual_card_id" 的引用必须以 ';' 分隔符结尾

      Error on line 1 of document  : 对实体 "virtual_card_id" 的引用必须以 ';' 分隔符结尾. CreateTime--2018年 ...

  8. python之函数用法file()

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法file() #file() #说明:file()内建函数它的功能等于open(),但 ...

  9. 【laravel5.4】vue分页删除

    1.a标签执行ajax删除,后台删除成功后,执行vue分页对象删除对应数据 VUE.js

  10. HDUOJ---1133(卡特兰数扩展)Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...