java 经纬度解析地址地理位置信息
2013-11-18 13:38
423 查看
/*** * 根据经伟度得到详细的地址信息 * @param x * @param y * @throws IOException * @throws UnsupportedEncodingException */ public String getaddressforxybyGooglehttpconnection(String x,String y) throws IOException { if(x.length() >9){x = x.substring(0,7);} if(y.length()>8){y = y.substring(0,6);} URL url = null; String mapurl="http://maps.google.cn/maps/geo?output=csv&key=abcdef&q=" +Float.parseFloat(y)/100000+ "," + Float.parseFloat(x)/100000 ; String address="无法从地理信息服务器上获得此位置的地理信息";//取地图的地址 StringBuffer strBuffer = new StringBuffer(); HttpURLConnection connection = null; DataInputStream in = null; try { url = new URL(mapurl); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setUseCaches(false); connection.setDefaultUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); connection.setConnectTimeout(1000); connection.setReadTimeout(1000); in = new DataInputStream(connection.getInputStream()); int all= in.available(); int code = connection.getResponseCode(); if(code != connection.HTTP_OK) { return address ; } else { byte[] b= new byte[all]; in.read(b); String strAddress= new String(b,"UTF-8"); //GBK 2011-04-28 String[] m_sAddress = strAddress.split(","); if (m_sAddress.length == 3) { address = m_sAddress[2]; } else { address = "无法获取地址"; } //address = new String(b,"UTF-8"); //GBK 2011-04-28 } connection.disconnect(); in.close(); } catch (Exception e) { address="无法从地理信息服务器上获得此位置的地理信息";//取地图的地址 } finally { connection.disconnect(); in.close(); } address = address.replace('"', ' '); address = address.replace("<?xml version= 1.0 encoding= GBK ?><R><code>0</code><msg>", ""); address = address.replace("</msg></R>", ""); return address; }
相关文章推荐
- 【Java】 java调用百度地图API根据地理位置中文获取经纬度 地址备忘
- java程序调用百度Geocoding API逆地址解析通过经纬度查询位置
- IP地址库解析——读取IP地址获得实际地理位置信息的java源码实现
- iOS开发——定位获取经纬度坐标,并反编码获得地理位置信息(具体地址,国家、省、市等)
- [百度地图] 获取用户地理位置信息并解析成地址
- 根据经纬度来获取地理位置信息demo
- java 接收解析微信公众号返回XML数据包,消息,地理位置
- PHP根据地理位置信息获取经纬度
- js实现百度地图定位于地址逆解析,显示自己当前的地理位置
- 项目源码--JAVA基于LBS地理位置信息应用的服务端
- iOS上地图通过地理位置经纬度找出城市等信息
- 根据经纬度来获取地理位置信息demo
- 百度地图的反地址解析(通过经纬度查询地址信息)
- IOS 经纬度 转换地理位置信息
- Android 通过经纬度获取地理位置信息
- java操作地理位置信息
- Android 如何获取手机经纬度和地理位置信息
- 【百度地图API】如何进行地址解析与反地址解析?——模糊地址能搜索到精确地理信息!
- 百度地图API根据某个经纬度值(地理坐标)查询对应的地址信息以及该地址周边的POI(Point of Interest,兴趣点)信息
- iOS中利用系统地图获取定位信息(经纬度/地理位置)