高德开放平台 | 高德地图API /** * 地址转经纬度 (高德地图Api转换) * @param address * @return */ public static String getLnglat(String address){ String geturl = "http://restapi.amap.com/v3/geocode/geo?key="+高德开放平台申请的key+"&address="+address; String location = ""; try { URL url = new URL(geturl); // 把字符串转换为URL请求地址 HttpURLConnection connection = (HttpURLConnection) url.openConnection();// 打开连接 connection.connect();// 连接会话 // 获取输入流 BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) {// 循环读取流 sb.append(line); } br.close();// 关闭流 connection.disconnect();// 断开连接 JSONObject a = JSON.parseObject(sb.toString()); //判断输入的位置点是否存在 System.out.println(sb.toString()); if(a.getJSONArray("geocodes").size()>0){ location=a.getJSONArray("geocodes").getJSONObject(0).get("location").toString(); } } catch (Exception e) { e.printStackTrace(); System.out.println("失败!"); } return location; }