您的位置:首页 > 移动开发 > Android开发

在android用Google Geocoding API服务解析地址(关键词:android/GPS/Geocoding API/getLocationFrom()返回null)

2011-03-18 18:43 507 查看
关键词:android/GPS/Geocoding API/getLocationFrom()返回null

 

 

打算做一个地址位置解析相关的程序,网上大都用的如下方法:

getFromLocation()与getFromLocationName()这两个函数是大家比较喜欢的,也是资料比较丰富的。

详情见如下链接:

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

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

 

但是,经本人试验发现关键步骤getFromLocation()/getFromLocationName()返回null值,在网上一搜发现很多人也出现相似情况:

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=59961&page=1#pid652205

 

 

万念俱灰!!!!!!

 

 

后面看文档才发现Google跟我们开了个玩笑:

 
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.


 

真够操蛋的还!

 

 

于是心灰意冷的我开始另辟蹊径:

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

感谢二楼!

 

 

于是来到了心中的圣地:

http://code.google.com/intl/zh-CN/apis/maps/documentation/geocoding/

差不多了?

 

 

还不够,google map解析出来的字段与上面链接说明的有些不一样,具体地址与各位层级位置的关系如下:

 
//address == CountryName + AdministrativeAreaName + LocalityName + ThoroughfareName


分别是国家/省份/城市/城市中的具体位置;

 

 

还有个Accuracy字节代表精度,这就因输入得到的经纬度值不同而不同了;

 

如:

http://ditu.google.com/maps/geo?q=您的Latitude,您的Longitude&output=xml&oe=utf8&hl=zh-CN&sensor=true&key=您的Map APIkey

其中,hl=zh-CN代表要返回中文,如果此约束会返回英式地址。

 

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

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小时吗?

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.
 

以上说明来自:http://www.smnirven.com/?p=39

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

 

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

http://hi.baidu.com/zdz8207/blog/item/a110830a6850c92ab0351d4a.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息