最近的一个项目中需要将坐标值转换为地理位置显示给用户,即将:
113.952078,22.562627

转换为:深圳市南山区科苑北路


目前网上提供这种功能接口的有:
一、百度“车联网API”
官方地址:http://developer.baidu.com/map/wiki/index.php?title=car/api/anti-geocoding

参考示例:
http://api.map.baidu.com/telematics/v3/reverseGeocoding?location=116.3017193083,40.050743859593&coord_type=gcj02&ak=E4805d16520de693a3fe707cdc962045

需要注册并获取开发者密钥(ak);
引用 每个Key限制5000次/天。若需升级访问次数,请发送邮件。
如果你再使用车联网里面的天气等,每次请求都需要计算次数,这样算下来,如果你的用户一天使用5次,那么只能容纳1000用户,这肯定是不行的。办法就是跟官方合作,发邮件吧!




二、阿里云
http://gc.ditu.aliyun.com/regeocoding?l=39.938133,116.395739&type=001

这个地址是阿里云地图提供的,无需注册,无访问次数限制,推荐!!!

使用样例:
public static void testUrlRes(String lat, String lng) throws IOException {// type 001 (100代表道路,010代表POI,001代表门址,111可以同时显示前三项)String path = "http://gc.ditu.aliyun.com/regeocoding?l=" + lat + ","+ lng + "&type=100";// 参数直接加载url后面URL url = new URL(path);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestProperty("contentType", "GBK");conn.setRequestMethod("GET");conn.setConnectTimeout(5000);if (conn.getResponseCode() == 200) { // 200表示请求成功InputStream is = conn.getInputStream(); // 以输入流的形式返回// 将输入流转换成字符串ByteArrayOutputStream baos = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;while ((len = is.read(buffer)) != -1) {baos.write(buffer, 0, len);}if (baos.size() < 1) {System.out.println("坐标请求异常.");return;}// 得出整个坐标反馈信息String jsonString = baos.toString();System.out.println("jsonString:"+jsonString);baos.close();is.close();// 转换成json数据处理// {"queryLocation":[39.938133,116.395739],"addrList":[{"type":"doorPlate","status":1,"name":"地安门外大街万年胡同1号","admCode":"110102","admName":"北京市,北京市,西城区,","addr":"","nearestPoint":[116.39546,39.93850],"distance":45.804}]}}}


三、高德
高德被阿里收购之后已经是一家了,后面肯定会以这个接口为准,上面阿里地图的那个地图后期估计会无法使用;
官方地址:http://lbs.amap.com/api/android-sdk/guide/geocode/
需要注册并获取key,其他没什么集成难度,按照说明文档进行即可;


最后提供一个联网获取json数据的方法:
public static String getJsonContent() {String urlString = "";try {urlString = URL + "&location="+"&ak=" + APP_KEY;} catch (Exception e1) {e1.printStackTrace();}try {// 获取HttpURLConnection连接对象URL url = new URL(urlString);HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();// 设置连接属性httpConn.setConnectTimeout(8000);httpConn.setDoInput(true);httpConn.setRequestMethod("GET");// 获取相应码int respCode = httpConn.getResponseCode();if (respCode == 200) {return ConvertStream2Json(httpConn.getInputStream());}} catch (MalformedURLException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return "";}private static String ConvertStream2Json(InputStream inputStream) {String jsonStr = "";// ByteArrayOutputStream相当于内存输出流ByteArrayOutputStream out = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;// 将输入流转移到内存输出流中try {while ((len = inputStream.read(buffer, 0, buffer.length)) != -1) {out.write(buffer, 0, len);}// 将内存流转换为字符串jsonStr = new String(out.toByteArray());} catch (IOException e) {e.printStackTrace();}return jsonStr;}

更多相关文章

  1. android java file 清理垃圾获取文件大小 删除文件等操作
  2. 通过adb shell dumpsys命令获取当前应用的component
  3. bt开发类
  4. uni-app之APP和小程序微信授权方法
  5. android adb root方法
  6. android webview中使用Java调用JavaScript方法并获取返回值
  7. android view setTag()和findViewWithTag()
  8. android wifi讲解 wifi列表显示
  9. Android(安卓)webview数据获取 webview抓取

随机推荐

  1. linux环境下写C++操作mysql(一)
  2. 蜂巢和数据库之间的完整性检查
  3. sql随机获获取数据
  4. 替换wordpress WP_POSTS表中post_date字
  5. mysql的count方法详解
  6. Spring+SpringMVC+MyBatis+easyUI整合基
  7. navicat for mysql 注册码,简简单单,一个搞
  8. MySQL数据库语法-多表查询练习一
  9. MySQL - 更改一行的时间值以匹配同一表
  10. php将图片以二进制形式保存到mysql数据库