Android Geocoder异常现象
来源:互联网 发布:sql语句怎么打印空格 编辑:程序博客网 时间:2024/03/29 02:11
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 下载获取,谢谢支持。
- Android Geocoder异常现象
- 分析:android.location.Geocoder
- Geocoder
- Android Location服务之Geocoder
- android cash现象分析,解决方案,异常重启
- Java中的异常现象
- nrf52832--功耗异常现象
- Timsort排序异常现象
- git clone 异常现象
- Android中文API(136) —— GeoCoder
- Android: How to get Address from geolocation using Geocoder
- Android 地理位置Location服务之LocationManager,Geocoder详解
- Android 地理位置Location服务之LocationManager,Geocoder详解
- android avd2.2获取街道信息:Geocoder, “the service is not available” && Geocoder返回List为null,得不到街道信息
- edid数据修改 异常现象
- 异常:代码的不正常现象
- Python Geocoder
- TCP连接一异常现象分析
- js省市二级下拉联动
- 基于Android手机开发平台的移动数字图书馆服务系统研究
- Scala微服务架构
- 关于scanf、sscanf和sscanf_s
- 全球定位系统在移动上的应用
- Android Geocoder异常现象
- 插入排序 C++实现
- android应用登录模块访问mysql数据库小记
- 实现查询地址和路线导航的代码
- Android控件之AutoCompleteTextView、MultiAutoCompleteTextView探究
- AIDL(进程间通信)
- sencha touch 创建app后,修改启动画面
- 如何编写高效的手持设备程序代码
- Day 6:在 Java 虚拟机上使用 Grails 进行快速 Web 开发