Geocoder类有根据地理名称得到address的方法:

getFromLocation()与getFromLocationName()这两个函数是大家比较喜欢的,也是资料比较丰富的。
但是在模拟器上运行的时候总是会出现service is not aviable的异常。这主要是模拟器的的事,不支持这项服务。

详情见如下链接:

Android 地图的地理编码与地理反编码:

http://www.eoeandroid.com/thread-63307-1-1.html

但是,经几天的试验发现关键步骤getFromLocation()/getFromLocationName()返回null值,或者得到的数组长度为0,或者报一些不为所知的异常,百度google后,去看了geocoder的官方文档:


view plaincopy to clipboardprint?
The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.
好像是说,需要一个服务支持,打算用geocoder的,还是考虑其它的吧,不要再浪费青春在这个的geocoder上了。



百度google了很长时间,不妨打开下面这个链接看看:

http://maps.google.com/maps/api/geocode/xml?address=北京&sensor=true




返回的是XML格式数据,看到你需要的数据吗?


XML Source Code<?xml version="1.0" encoding="UTF-8"?> <GeocodeResponse> <status>OK</status> <result> <type>locality</type> <type>political</type> <formatted_address>中国北京</formatted_address> <address_component> <long_name>北京</long_name> <short_name>北京</short_name> <type>locality</type> <type>political</type> </address_component> <address_component> <long_name>北京市</long_name> <short_name>北京市</short_name> <type>administrative_area_level_1</type> <type>political</type> </address_component> <address_component> <long_name>中国</long_name> <short_name>CN</short_name> <type>country</type> <type>political</type> </address_component> <geometry> <location> <lat>39.9042140</lat> <lng>116.4074130</lng> </location> <location_type>APPROXIMATE</location_type> <viewport> <southwest> <lat>39.6612714</lat> <lng>116.0119343</lng> </southwest> <northeast> <lat>40.2164962</lat> <lng>116.7829835</lng> </northeast> </viewport> <bounds> <southwest> <lat>39.6612714</lat> <lng>116.0119343</lng> </southwest> <northeast> <lat>40.2164962</lat> <lng>116.7829835</lng> </northeast> </bounds> </geometry> </result> </GeocodeResponse>

还有一些关于用google map解析地址的前提条件:


view plaincopy to clipboardprint?
Google Geocoding API 的使用有限制,即,每天 2,500 个地理位置查询请求。(Google Maps API Premier 用户每天最多可执行 100,000 个请求。)强制执行此限制是为了防止滥用和/或重复使用 Google Geocoding API。以后可能对此限制进行更改,而无需另行通知。此外,我们还强制设定了请求速率限制,以防滥用此服务。如果您超过了 24 小时的限制或者滥用此服务,Google Geocoding API 可能会暂停为您服务。如果您继续无视这个限制,将会阻止您对 Google Geocoding API 的访问。 请注意:Google Geocoding API 只能与 Google Maps 配合使用;不能只进行地址解析而不在地图上显示结果。有关允许的用法的完整详细信息,请参见 Google Maps API 服务条款许可限制。


"如果您超过了 24 小时的限制或者滥用此服务,Google Geocoding API 可能会暂停为您服务。"

不明白这句是什么意思!是开发者使用此服务的总时间不能超过24小时吗?


view plaincopy to clipboardprint?
One caveat before we get started: reverse geocoding is very resource intensive on Google’s side, and they will block your api calls if make too many requests within a certain amount of time. So, you want to make sure your application doesn’t fire requests too frequently – for my example I only send the request when users press a button.


大致意思是一个IP地址不能在短时间内向服务器频繁发送请求,否则应用程序会被禁用解析服务!

但此限制是针对单独一个IP地址而言,所以我们可以通过使用客户端地址解析,可以确保这些限制分别应用到每个用户,而不是针对由所有用户生成的总请求量。若是服务器发送请求的话可以将请求结果缓存在服务器端以响应客户端请求

:博客涉及的源码请在千寻资源库:www.qxzyk.com 下载获取,谢谢支持。

更多相关文章

  1. Android(安卓)学习项目开发案例
  2. Android(安卓)整合新浪微博SDK问题
  3. android 清理缓存
  4. Android(安卓)ScrollView嵌套ScrollView滚动的问题解决办法
  5. android 科大讯飞语音唤醒demo
  6. Android(安卓)DOM 解析 xml
  7. Android(安卓)图片选择器PictureSelector
  8. Android用自己的app替换Launcher
  9. Android(安卓)打电话,发短信,调用系统浏览器

随机推荐

  1. 一条语句简单解决“每个Y的最新X”的经典
  2. 在查询结果中添加一列表示记录的行数的sq
  3. 精妙的SQL和SQL SERVER 与ACCESS、EXCEL
  4. 关于Select Where In 的排序问题
  5. sqlserver 复制表 复制数据库存储过程的
  6. SuperSocket 信息: (SpnRegister) : Erro
  7. PLSQL连接oracle数据库过程图解
  8. 将count(*)值写入另一个表中的方法
  9. sql中varchar和nvarchar的区别与使用方法
  10. 解决SQL Server虚拟内存不足情况