Android 根据坐标获取地址
来源:互联网 发布:韩代淘宝知乎 编辑:程序博客网 时间:2024/05/16 23:53
Android中根据坐标获取地址,一般用Geocoder,大概像下面这样:
try{ Geocoder geo = new Geocoder(NewCommentActivity.this, Locale.getDefault()); List<Address> addresses = geo.getFromLocation(23.0897174,113.3116872, 1); if (addresses.isEmpty()) { Log.i("location", "addressed is Empty"); } else { if (addresses.size() > 0) { Log.i("location", addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName()); } } }
当我使用这段代码在真机上运行时,报错:
java.io.IOException:Sevice not Available
at android.location.Geocoder.getFromLocation
Google了一下,都说是在模拟器上才有这个问题,真机不会有此问题。但我确确实实在真机上遇到了这个问题。
查看Android官方文档,发现人家已经说的很明白了:
The Geocoder API is available for this purpose. Note that behind the scene, the API is dependent on a web service. If such service is unavailable on the device, the API will throw a "Service not Available exception" or return an empty list of addresses. A helper method calledisPresent() was added in Android 2.3 (API level 9) to check for the existence of the service.
看来对于没有这个服务的机型,确实是用不了这个方法的。那只能另辟蹊径了。在网上找到另外的方法:
访问Google的这个URL可以获得地址信息的JSON字符串。
String url = String.format("http://ditu.google.cn/maps/geo?output=json&key=abc&q=%s,%s", latitude, longitude);
- Android 根据坐标获取地址
- android 根据坐标获取RGB
- 百度地图根据坐标获取地址信息
- Android根据经纬度获取地址
- android 根据地址获取经纬度
- Android根据地址获取经纬度,根据经纬度
- Android 根据坐标获取控件方法
- Android 根据坐标获取控件方法
- Android 根据IP地址获取城市
- Android根据经纬度获取地址,眼前一亮
- Android根据已知的经纬度坐标获取当前位置
- IOS 根据地理位置获取坐标或根据坐标获取地理位置
- 设置marker拖拽并根据坐标,反地理获取地址详情
- 根据地址获取经纬度
- 根据IP获取地址
- 根据ip获取地址
- 根据ip获取地址
- 根据地址获取经纬度
- 过滤字符串中的HTML符号
- 我指间的刺青是对你的誓言
- ping某域名的整个流程
- Linux目录架构详解
- SP 中的错误处理
- Android 根据坐标获取地址
- Linux C程序调用系统命令
- 关于Alipay支付宝接口(Java版)
- 展讯智能机平台8810的编译脚本解析
- 单选/多选/下拉框
- case语句
- ImageView控件开发效果总结(边框效果,滤镜效果)
- Asp.Net读取excel文件的时候 出错提示:外部表不是预期的格式 解决方案
- Qt 图形特效(Graphics Effect)模糊,变色,透明和阴影