首页 经纬度地址转换 经纬度地址转换示例代码 地址转经纬度[Java]

地址转经纬度示例代码[Java]

作者:xiezhongpian 阅读数:1519 上传时间:2017-05-09

地址转经纬度

package api.jisuapi.geoconvert;

import java.net.URLEncoder;

import api.util.HttpUtil;
import net.sf.json.JSONObject;

public class Addr2coord {

	public static final String APPKEY = "your_appkey_here";// 你的appkey
	public static final String URL = "https://api.jisuapi.com/geoconvert/addr2coord";
	public static final String address = "益乐路39号";//utf8
	public static final String type = "baidu";//可选 google baidu

	public static void Get() throws Exception {
		String result = null;
		String url = URL + "?address=" + URLEncoder.encode(address,"utf-8") + "&type=" + type + "&appkey=" + APPKEY;

		try {
			result = HttpUtil.sendGet(url, "utf-8");
			JSONObject json = JSONObject.fromObject(result);
			if (json.getInt("status") != 0) {
				System.out.println(json.getString("msg"));
			} else {
				JSONObject resultarr = json.optJSONObject("result");
				String lat = resultarr.getString("lat");
				String lng = resultarr.getString("lng");
				String type = resultarr.getString("type");
				String address = resultarr.getString("address");
				String fulladdress = resultarr.getString("fulladdress");
				String precise = resultarr.getString("precise");
				String confidence = resultarr.getString("confidence");
				String level = resultarr.getString("level");
				System.out.println(address + " " + type + " " + lat + " " + lng + " " + fulladdress + " " + precise
						+ " " + confidence + " " + level);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}