根据经纬度来获取地理位置信息demo
2013-08-23 11:14
615 查看
package com.map; import java.io.DataInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; public class Address { /*** * 根据经伟度得到详细的地址信息 * @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; } public static void main(String[] args) { Address address = new Address(); try { String result = address.getaddressforxybyGooglehttpconnection("30", "120"); System.out.println(result); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- 根据经纬度来获取地理位置信息demo
- 根据GPS获得的经纬度来获取地理位置信息
- 根据经纬度获取地理位置名称省、市等信息
- PHP根据地理位置信息获取经纬度
- iOS开发——定位获取经纬度坐标,并反编码获得地理位置信息(具体地址,国家、省、市等)
- CLGeocoder 根据地理位置获取经纬度,根据经纬度获取地理位置
- iOS中利用系统地图获取定位信息(经纬度/地理位置)
- 地理编码反地理编码, 根据地名获取经纬度等信息
- Android根据IP获取地理位置,精确到经纬度
- 百度地图,根据地图上任意一点的经纬度获取周边最近的POI位置信息
- Android 如何获取手机经纬度和地理位置信息
- java调用百度地图API通过URL根据地理位置中文处理返回值获取经纬度
- java调用百度地图API根据地理位置获取经纬度
- Android app接入百度地图:禁用手势、模式切换、根据经纬度获取位置信息
- java调用百度地图API根据地理位置中文获取经纬度
- 【Java】 java调用百度地图API根据地理位置中文获取经纬度 地址备忘
- java调用百度地图API根据地理位置中文获取经纬度
- gprs 获取基站信息,根据基站信息定位地理位置(基站免费查询接口)
- 通过经纬度获取地理位置信息
- 百度地图_根据地图上标记位置获取街道信息,以及经纬度信息