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

用百度地图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

猜你喜欢

转载自blog.csdn.net/ardo_pass/article/details/83006756