通过google map批量进行地址解析成坐标
public static void main(String args[]){ Thread thread=new Thread(); List list=new ArrayList();//list中存放的是要查询的地址 for(int i=0;i<list.size();i++){ String address=list.get(i); String ss=URLEncoder.encode(address,"UTF-8");//对地址进行编码 thread.sleep(5000);//要等待几秒中,如果查询速度太快,google地图会查询不出来,严重会封ip String mess=sendGet("http://ditu.google.cn/maps/geo", "output=csv&key=abcdef&q="+ss); //上边是通过ouput=csv输出的,还有json,xml等形式(如果需要可以查看谷歌地图中介绍,另一篇地址解析文章中有地址) System.out.println(mess); } } public static String sendGet(String url, String param) { String result = ""; BufferedReader in = null; try { String urlName = url + "?" + param; URL realUrl = new URL(urlName); // 打开和URL之间的连接 URLConnection conn = realUrl.openConnection(); // 设置通用的请求属性 conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); // 建立实际的连接 conn.connect(); // 获取所有响应头字段 Map map = conn.getHeaderFields(); // 遍历所有的响应头字段 for (String key : map.keySet()) { // System.out.println(key + "--->" + map.get(key)); } // 定义BufferedReader输入流来读取URL的响应 in = new BufferedReader( new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("发送GET请求出现异常!" + e); e.printStackTrace(); } // 使用finally块来关闭输入流 finally { try { if (in != null) { in.close(); } } catch (IOException ex) { ex.printStackTrace(); } } return result; }
本文地址:http://www.coolaf.com/article/31 转载请注明本文地址