百度地图根据地址获取经纬度

public static String getCoordinate(String address) throws IOException{ 
		String lngAndLag="";
		String key = "f247cdb592eb43ebac6ccd27f796e2d2"; 
		String url = String 
		.format("http://api.map.baidu.com/geocoder?address=%s&output=json&key=%s", 
		address, key); 
		DefaultHttpClient httpclient=new DefaultHttpClient(); 
		HttpPost httppost=new HttpPost(url);  
		HttpResponse response=httpclient.execute(httppost);  
		HttpEntity httpEntity= response.getEntity();  
		String content = EntityUtils.toString(httpEntity, "UTF-8");  
		if(StringUtil.isNotNullAndNotEmpty(content)){
			JSONObject json=JSONObject.fromObject(content);
		 String resultStr=json.get("result").toString();
		 if(!resultStr.equals("[]")){
			 JSONObject result=json.getJSONObject("result");
			 JSONObject location=JSONObject.fromObject(result.get("location"));
			 lngAndLag=location.get("lng")+","+location.get("lat");
		 }
		}
		httpclient.close();
		 return lngAndLag;
	} 

你可能感兴趣的:(java,web开发)