[java]百度API简单操作
来源:互联网 发布:wifi如何绑定mac地址 编辑:程序博客网 时间:2024/06/05 06:00
//从输入的地址解析获取经纬度public Map<String, BigDecimal> getLatAndLngByAddress(String addr){ String address = ""; String lat = ""; String lng = ""; try { address = java.net.URLEncoder.encode(addr,"UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } String url = String.format("http://api.map.baidu.com/geocoder/v2/?" +"ak=4rcKAZKG9OIl0wDkICSLx8BA&output=json&address=%s",address); URL myURL = null; URLConnection httpsConn = null; //进行转码 try { myURL = new URL(url); } catch (MalformedURLException e) { } try { httpsConn = (URLConnection) myURL.openConnection(); if (httpsConn != null) { InputStreamReader insr = new InputStreamReader( httpsConn.getInputStream(), "UTF-8"); BufferedReader br = new BufferedReader(insr); String data = null; if ((data = br.readLine()) != null) { lat = data.substring(data.indexOf("\"lat\":") + ("\"lat\":").length(), data.indexOf("},\"precise\"")); lng = data.substring(data.indexOf("\"lng\":") + ("\"lng\":").length(), data.indexOf(",\"lat\"")); } insr.close(); } } catch (IOException e) { } Map<String, BigDecimal> map = new HashMap<String, BigDecimal>(); map.put("lat", new BigDecimal(lat)); map.put("lng", new BigDecimal(lng)); return map;}
0 0
- [java]百度API简单操作
- 百度地图API基础操作--简单定位篇
- 百度地图API简单应用
- 百度地图API简单实例
- 百度地图api简单使用
- HBase简单API操作
- 使用Java Api 对HBase进行简单操作
- Elasticsearch简单使用系列--使用Java API进行CRUD操作
- Java调用百度地图API
- 百度地图API 一些简单方法
- “百度地图JavaScript API”简单实例开发
- 百度地图API 简单使用技巧一
- 百度地图api的简单应用
- 百度地图API简单小例
- 百度翻译API的简单调用
- 百度地图API的简单应用
- 百度语音REST API -- 简单Demo
- 详解百度地图API之地图操作
- Xcode8 以后如何使用 插件
- 机器学习群内分享: 机器学习入门的几个问题
- JAVA-类的访问控制
- $.ajax()方法详解
- php $_SERVER中的SERVER_NAME 和HTTP_HOST的区别
- [java]百度API简单操作
- @OneToMany或@ManyToOne的用法-annotation关系映射篇
- 学习资料汇总(持续更新)
- Spring--IoC--从applicationContext容器中获取对象
- android 为什么不建议使用Enum
- #695 – 实现一个简单的拖拽(Implementing Drag-and-Drop Behavior)
- 每天一个Linux命令(49):ifconfig
- 一张图了解:sass
- Distributed tensorflow实现原理