java实现根据经纬度获取具体地址
2018-02-12 11:08
423 查看
--java类
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* @author
* @date 2018年2月12日 上午9:25:18
* @explain 根据经纬度获取地址
*/
public class MyGetLocation {
public static void main(String[] args){
/**
* 获取位置
* @param log 大: 纬度
* @param lat 小:经度
* @return
*/
public static String getAdd(String log,String lat) {
/**
* 阿里云根据经纬度获取地区名接口:
* http://gc.ditu.aliyun.com/regeocoding?l=39.938133,116.395739&type=001
* 阿里云根据地区名获取经纬度接口:
* http://gc.ditu.aliyun.com/geocoding?a=苏州市
*/
/** type(100代表道路,010代表POI,001代表门址,111前面都是) */
String urlString = "http://gc.ditu.aliyun.com/regeocoding?l="+lat+","+log+"&type=010";
String res = "";
try {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setRequestMethod("POST");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));
String line;
while((line = in.readLine())!= null) {
res += line+"\n";
}
in.close();
} catch (Exception e) {
// TODO: handle exception
System.out.println("error in wapaction,and e is "+e.getMessage());
}
System.out.println(res);
return res;
}
public static JSONObject getAddrObj() {
String add = getAdd("121.4015340316","31.1721005574");
JSONObject jsonObject = JSONObject.fromObject(add);
JSONArray jsonArray = JSONArray.fromObject(jsonObject.getString("addrList"));
JSONObject addrObj = JSONObject.fromObject(jsonArray.get(0));
return addrObj;
}
}
--pom.xml
--管理依赖 cmd运行 mvn compile 编译项目
<!-- Json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<!--json-lib-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* @author
* @date 2018年2月12日 上午9:25:18
* @explain 根据经纬度获取地址
*/
public class MyGetLocation {
public static void main(String[] args){
/**
* 获取位置
* @param log 大: 纬度
* @param lat 小:经度
* @return
*/
public static String getAdd(String log,String lat) {
/**
* 阿里云根据经纬度获取地区名接口:
* http://gc.ditu.aliyun.com/regeocoding?l=39.938133,116.395739&type=001
* 阿里云根据地区名获取经纬度接口:
* http://gc.ditu.aliyun.com/geocoding?a=苏州市
*/
/** type(100代表道路,010代表POI,001代表门址,111前面都是) */
String urlString = "http://gc.ditu.aliyun.com/regeocoding?l="+lat+","+log+"&type=010";
String res = "";
try {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setRequestMethod("POST");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));
String line;
while((line = in.readLine())!= null) {
res += line+"\n";
}
in.close();
} catch (Exception e) {
// TODO: handle exception
System.out.println("error in wapaction,and e is "+e.getMessage());
}
System.out.println(res);
return res;
}
public static JSONObject getAddrObj() {
String add = getAdd("121.4015340316","31.1721005574");
JSONObject jsonObject = JSONObject.fromObject(add);
JSONArray jsonArray = JSONArray.fromObject(jsonObject.getString("addrList"));
JSONObject addrObj = JSONObject.fromObject(jsonArray.get(0));
return addrObj;
}
}
--pom.xml
--管理依赖 cmd运行 mvn compile 编译项目
<!-- Json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<!--json-lib-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
相关文章推荐
- java工具类(一)之服务端java实现根据地址从百度API获取经纬度
- 服务端java实现根据地址从百度API获取经纬度
- java 根据经纬度获取地址实现代码
- java工具类(一)之服务端java实现根据地址从百度API获取经纬度
- java 根据经纬度获取百度地图地址
- 百度地图 java 根据地址获取经纬度
- Android编程实现根据经纬度查询地址并对获取的json数据进行解析的方法
- java 根据经纬度获取地址
- java根据地址获取百度API经纬度
- 根据ip地址和子网掩码获取广播地址的java实现
- 百度地图API根据具体地址获取经纬度
- java根据经纬度获取地址
- Java 实现根据 IP 地址获取地理位置的代码分享
- java 根据经纬度获取地址
- 【Java】 java调用百度地图API根据地理位置中文获取经纬度 地址备忘
- java google map 根据经纬度 获取地址
- 根据经纬度查询地址并对获取的json数据进行解析
- (java功能篇)谷歌获取地址经纬度
- JAVA通过物理地址获取经纬度
- google maps 新接口: 根据经纬度获取当前地址