文档章节

Android 逆地理编码geocoding

iSnowFlake
 iSnowFlake
发布于 2015/10/19 16:15
字数 1226
阅读 1220
收藏 6

       地理编码和逆地理编码都差不多,这里总结一下逆地理编码,根据经纬度解析出地址。Android这边逆地理编码方式主要是两种(不包含高德,百度)一种是使用Android 系统的Geocoder类来解析(这种方法过时而且不实用,经常失败,在中国和印尼都有测试数据,而且部分手机阉割了,这种方法如果想要了解请参考http://dev.10086.cn/news/technologyproduct/4859.html);另外一种是使用Google 的web api;

        请开VPN点击体验:http://maps.google.com/maps/api/geocode/json?latlng=39.910093,116.403945&language=zh-CN&sensor=false;详细的参数请参见Google 官方说明:https://developers.google.com/maps/documentation/geocoding/intro?hl=zh-cn;这里介绍Android的使用:

1.用于结果的回调
public interface LocationCallBack {
 void geoCodeSuccess(String address);
 void geoCodeFailure(String address); 
}
2.geocode 的封装
/**
 * 
 * 
 * @author anylife.zlb@gmail.com
 */
public class BipGeoCoder {
 private List<RealTimeAddrGeoDataBean> realTimeAddrGeoDataBeans=null;
 private RequestQueue mQueue = null;
 private Context context;
 private String address;
 
    public BipGeoCoder(Context context) {
  super();
  this.context = context;
 }
 /**
     * 获取地址通过Web service
     * 
     */   
    public void getAddress(final double latitude, final double longitude,final String defAddress,final LocationCallBack locationCallBack){     
     
        String requestUrl=VolleyParamsBuild.newBuilder().putParam("language", "en-ww")  //en-ww 可以根据业务逻辑替换为不同的国家语言
                                                  .putParam("latlng", latitude+","+longitude)
                                                  .build().toString();
        address=defAddress;
       mQueue=GetHttpUtils.getInstance(context).getRequestQueue();
  JsonObjectRequest stringRequest = new JsonObjectRequest(requestUrl, null,
    new Response.Listener<JSONObject>() {
     @Override
     public void onResponse(JSONObject response) {
         TypeFactory tf =  JsonUtil.getMapper().getTypeFactory();
         JavaType jt = tf.constructParametricType(List.class, RealTimeAddrGeoDataBean.class);
         try { 
       String json = response.getString("results").toString();
       realTimeAddrGeoDataBeans = JsonUtil.getMapper().readValue(json, jt);
         } catch (JsonParseException e) {
          e.printStackTrace();
         } catch (JsonMappingException e) {
          e.printStackTrace();
         } catch (IOException e) {
          e.printStackTrace();
         } catch (JSONException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } 
                    
         if(realTimeAddrGeoDataBeans!=null&&realTimeAddrGeoDataBeans.size()>0){
          address=realTimeAddrGeoDataBeans.get(0).getFormatted_address();
          //这里应该控制再次访问刷新地址。
         }  
         
         locationCallBack.geoCodeSuccess(address);
//         Log.d("Addr","Geocoding:"+address);
     }
    }, new Response.ErrorListener() {
     @Override
     public void onErrorResponse(VolleyError error) {
         locationCallBack.geoCodeFailure(address);
      Log.e("Addr",error.toString());
     }
    });
  mQueue.add(stringRequest);
    } 
 }
3.使用Demo

 new BipGeoCoder(getActivity()).getAddress(obj.getLatitude(), obj.getLongitude(), locationdef,new LocationCallBack() {
   
   @Override
   public void geoCodeSuccess(String address) {
    // TODO Auto-generated method stub
    Log.e("Addr","geoCodeSuccess:"+address);

      }
   
   @Override
   public void geoCodeFailure(String address) {
    // TODO Auto-generated method stub
    Log.e("Addr","geoCodeFailure:"+address);

   }
   });

最后:

以下内容来自Googlehttps://developers.google.com/maps/documentation/geocoding/intro?hl=zh-cn ,使用前请翻墙

-----------------------------------------------------------

The Google Maps Geocoding API

This service is also available as part of the Google Maps JavaScript API, or the Java and Python client libraries.

What is Geocoding?

Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers on a map, or position the map.

Reverse geocoding is the process of converting geographic coordinates into a human-readable address. The Google Maps Geocoding API's reverse geocoding service also lets you find the address for a given place ID.

The Google Maps Geocoding API provides a direct way to access these services via an HTTP request.

Before You Begin

This document is intended for website and mobile developers who want to use geocoding data within maps provided by one of the Google Maps APIs.

This service is generally designed for geocoding static (known in advance) addresses for placement of application content on a map; this service is not designed to respond in real time to user input, for example. For dynamic geocoding (for example, within a user interface element), consult the documentation for the Google Maps JavaScript API Client Geocoder and/or the Google Play services Location APIs.

Geocoding is a time and resource intensive task. Whenever possible, pre-geocode known addresses (using the Google Maps Geocoding API described here or another geocoding service), and store your results in a temporary cache of your own design.

To use the Google Maps Geocoding API, you need an API key.

GET A KEY USAGE LIMITS

Google Maps Geocoding API Request Format

A Google Maps Geocoding API request must be of the following form:

https://maps.googleapis.com/maps/api/geocode/output?parameters

where output may be either of the following values:

  • json (recommended) indicates output in JavaScript Object Notation (JSON)

  • xml indicates output as XML

To access the Google Maps Geocoding API over HTTP, use:

http://maps.googleapis.com/maps/api/geocode/output?parameters

HTTP is not recommended for applications that include sensitive user data, such as a user's location, in requests.

Some parameters are required while some are optional. As is standard in URLs, parameters are separated using the ampersand (&) character.

Google Maps API for Work users must include valid client and signature parameters with their Geocoding requests. Please refer to Google Maps API for Work Web Services for more information.

The rest of this page describes geocoding and reverse geocoding separately, because different parameters are available for each type of request.

Geocoding (Latitude/Longitude Lookup)

Required parameters in a geocoding request:

  • address — The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided. Please refer to the FAQ for additional guidance. 
         or 
    components — A component filter for which you wish to obtain a geocode. See Component Filtering for more information. The components filter will also be accepted as an optional parameter if an address is provided.

  • key — Your application's API key. This key identifies your application for purposes of quota management. Learn how to get a key.

Optional parameters in a geocoding request:

  • bounds — The bounding box of the viewport within which to bias geocode results more prominently. This parameter will only influence, not fully restrict, results from the geocoder. (For more information see Viewport Biasing below.)

  • language — The language in which to return results. See the list of supported domain languages. Note that we often update supported languages so this list may not be exhaustive. Iflanguage is not supplied, the geocoder will attempt to use the native language of the domain from which the request is sent wherever possible.

  • region — The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder. (For more information see Region Biasing below.)

  • components — The component filters, separated by a pipe (|). Each component filter consists of a component:value pair and will fully restrict the results from the geocoder. For more information see Component Filtering, below.

© 著作权归作者所有

共有 人打赏支持
iSnowFlake
粉丝 34
博文 93
码字总数 53328
作品 0
深圳
高级程序员
私信 提问
加载中

评论(1)

iSnowFlake
iSnowFlake
(retrofit demo :https://github.com/AnyLifeZLB/Retrofit2.0_Demo)
Android 上使用Google Maps 的教程

Creating the Project Using Eclipse, create a new Android project and name GoogleMaps as shown in Figure 1. Figure 1 Creating a new Android project using Eclipse Obtaining a Maps......

小卒过河
2011/08/19
2.1K
4
arcgis server10.2.2之地理编码服务发布Create Address Locator

1、地理编码工具(Geocoding Tools)locator制作 打开arcCatalog,找到工具箱ArcToolbox中的Geocoding Tools---Create Address Locator,界面如下: 2、locator已经制作完成,接下来就是发布...

sinat_34719507
2017/01/16
0
0
SVGeocoder

SVGeocoder 是对 Google Geocoding Service 的简单 Cocoa 封装,它可以让你迅速的进行地理编码和反向地理编码地址和坐标。It is block-based, uses NSURLConnection internally as well as J...

匿名
2012/08/13
460
0
Google Map For Android

android.location 包提供了一些工具来实现基于位置的服务。主要包括 Geocoder 类和LocationManager服务。首先介绍 Geocoder。 1.使用Android进行地理编码 如果打算使用地图做一些实际的事情,...

Mr.yangl
2011/10/08
0
0
android定位和地图开发实例

在android开发中地图和定位是很多软件不可或缺的内容,这些特色功能也给人们带来了很多方便。 首先介绍一下地图包中的主要类: MapController : 主要控制地图移动,伸缩,以某个GPS坐标为中...

冯京宝
2012/08/28
0
0

没有更多内容

加载失败,请刷新页面

加载更多

如何在Chrome浏览器中启动deviceready事件(尝试调试phonegap项目)?

我正在开发PhoneGap应用程序,我希望能够在Chrome中调试它,而不是在电话上调试。但是,我在onGetReady()函数中初始化我的代码,该函数在PhoneGap触发“deviceready”事件时触发。由于Chr...

kisshua
19分钟前
1
0
支付宝客户端架构分析:自动化日志收集及分析

摘要: 《支付宝客户端架构解析》系列将从支付宝客户端的架构设计方案入手,带领大家进一步了解支付宝在客户端架构上的迭代与优化历程。 小蚂蚁说: 《支付宝客户端架构解析》系列将从支付宝...

阿里云官方博客
22分钟前
1
0
nginx中部署vue打包后的静态文件

如何在nginx中部署静态资源就不描述了, 请看我的这篇博客 将vue脚手架项目打包后的静态文件放到nginx上, 发现有个问题, 即url上有#, 怎么去掉这个#呢. 1 项目中router的mode 路由的mode要为h...

克虏伯
40分钟前
7
0
JS容易理解错误的地方

在这端代码执行的末尾,你会不会hi变量回事函数中的hi了?你会不会认为这不是按引用传递了? 对值传递和引用传递产生质疑了? 1 var hi = {};2 function sayHello(hi) { ...

器石_
41分钟前
4
0
Java开发学习--MongoDB

之前只学过sql,第一次使用非关系型数据库。以前对于关系型数据库与非关系型数据库的概念很模糊,通过这次的学习对这两者有了一个清晰的概念。 主键 在MongoDB中,主键名叫"_id",如果在生成...

微笑向暖wx
45分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部