欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

百度地图api根据详细地址反查坐标

程序员文章站 2022-06-10 12:49:33
...

用百度地图api根据详细地址反查坐标

/**
	 * 根据详细地址反查坐标
	 * @param args
	 */
	public static void main(String[] args) {
		String address = "南开-南开区西湖道与南丰路交口东侧-南开区西湖里小区-2号楼-1门-3层";
		JSONObject j = RestUtil.httpRequest(new RestParam("http://api.map.baidu.com/geocoder/v2/?output=json&ak=1XjLLEhZhQNUzd93EjU5nOGQ&address="+address, 
	    		"GET", "", "http", "", "ardo"));
		JSONObject resuleObject = JSONObject.fromObject(j.getString("result"));
		String location = resuleObject.get("location")+"";
		JSONObject locObject = JSONObject.fromObject(location);
		String lng = locObject.get("lng")+"";
		String lat = locObject.get("lat")+"";
		System.out.println(resuleObject.toString());
		System.out.println("经度:"+lng+" "+"纬度:"+lat);
	}

输出结果:

{"location":{"lng":117.17403,"lat":39.124958},"precise":1,"confidence":80,"comprehension":95,"level":"地产小区"}
经度:117.17403 纬度:39.124958