您的位置:首页 > 其它

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

2016-06-30 10:19 543 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: