百度地图api根据地址获取所属省市

# 百度地图(2)

准备工作就不详述了,请看上一篇介绍。直接上代码:

public static void main(String[] args) {

		Map params = new HashMap();
		List list = new ArrayList();
		String originDouble = HttpClientUtil
				.doGet("http://api.map.baidu.com/geocoder/v2/?output=json&ak=你的ak&address="
						+ "开封市顺河回族区北门大街");
		com.alibaba.fastjson.JSONObject jsonObjectOri = com.alibaba.fastjson.JSONObject.parseObject(originDouble);
		String status = jsonObjectOri.getString("status");
		if (status == "0" || "0".equals(status)) {// 解析的地址不为空时 进行值的获取
			String oriLng = jsonObjectOri.getJSONObject("result").getJSONObject("location").getString("lng");// 经度值
			String oriLat = jsonObjectOri.getJSONObject("result").getJSONObject("location").getString("lat");// 纬度值
			String location = oriLat + "," + oriLng;
			String result = HttpClientUtil.doGet(
					"http://api.map.baidu.com/geocoder/v2/?output=json&ak=Orl7UwggqFGWGoxEfHMV5qr5fSnVM9Nf&location="
							+ location);
			com.alibaba.fastjson.JSONObject jsonObjectAdds = com.alibaba.fastjson.JSONObject.parseObject(result);
			String province = jsonObjectAdds.getJSONObject("result").getJSONObject("addressComponent")
					.getString("province");// 省
			String city = jsonObjectAdds.getJSONObject("result").getJSONObject("addressComponent").getString("city");// 市

			System.out.println("province:" + province);
			System.out.println("city:" + city);
		}
	}
 
  

百度地图api根据地址获取所属省市_第1张图片
百度地图api根据地址获取所属省市_第2张图片

你可能感兴趣的:(Map)