一、HttpClient --- 百度地图LBS云存储
public class BaiduMapCloudStorageTest {
// 创建表
@Test
public void demo1() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v3/geotable/create");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", "mytable1"));
nameValuePairs.add(new BasicNameValuePair("geotype", "1"));
nameValuePairs.add(new BasicNameValuePair("is_published", "1"));
nameValuePairs.add(new BasicNameValuePair("ak", "xxxxxx"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 查询表
public void demo2() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geodata/v3/geotable/list?ak=xxxxxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 查询表结构
public void demo3() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geodata/v3/geotable/detail?id=153944&ak=xxxxxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 创建列
public void demo4() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v3/column/create");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("geotable_id", "153944"));
nameValuePairs.add(new BasicNameValuePair("name", "名称"));
nameValuePairs.add(new BasicNameValuePair("key", "name"));
nameValuePairs.add(new BasicNameValuePair("type", "3"));
nameValuePairs.add(new BasicNameValuePair("max_length", "512"));
nameValuePairs.add(new BasicNameValuePair("is_sortfilter_field", "0"));
nameValuePairs.add(new BasicNameValuePair("is_search_field", "1"));
nameValuePairs.add(new BasicNameValuePair("is_index_field", "1"));
nameValuePairs.add(new BasicNameValuePair("is_unique_field", "1"));
nameValuePairs.add(new BasicNameValuePair("ak", "xxxxxx"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 查询列
public void demo5() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geodata/v3/column/list?geotable_id=153944&ak=xxxxxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 查询指定id列
public void demo6() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geodata/v3/column/detail?id=265695&geotable_id=153944&ak=xxxxxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 修改列
public void demo7() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v3/column/update");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", "265695"));
nameValuePairs.add(new BasicNameValuePair("geotable_id", "153944"));
nameValuePairs.add(new BasicNameValuePair("name", "描述"));
nameValuePairs.add(new BasicNameValuePair("key", "name"));
nameValuePairs.add(new BasicNameValuePair("type", "3"));
nameValuePairs.add(new BasicNameValuePair("max_length", "512"));
nameValuePairs.add(new BasicNameValuePair("is_sortfilter_field", "0"));
nameValuePairs.add(new BasicNameValuePair("is_search_field", "1"));
nameValuePairs.add(new BasicNameValuePair("is_index_field", "1"));
nameValuePairs.add(new BasicNameValuePair("is_unique_field", "1"));
nameValuePairs.add(new BasicNameValuePair("ak", "xxxxxx"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 创建数据 (create poi)
public void demo8() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v3/poi/create");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("geotable_id", "153944"));
nameValuePairs.add(new BasicNameValuePair("title", "XXX"));
nameValuePairs.add(new BasicNameValuePair("address", "xxx"));
nameValuePairs.add(new BasicNameValuePair("latitude", "xxx.xxx"));
nameValuePairs.add(new BasicNameValuePair("longitude", "xxx.xxx"));
nameValuePairs.add(new BasicNameValuePair("coord_type", "3"));
nameValuePairs.add(new BasicNameValuePair("ak", "xxxxxx"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 查询指定条件数据(poi)
public void demo9() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geodata/v3/poi/list?geotable_id=153944&ak=xxxxxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 查询指定id的数据(poi)
public void demo10() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geodata/v3/poi/detail?id=1822675338&geotable_id=153944&ak=xxxxxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 修改数据 (update poi)
public void demo11() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v3/poi/update");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", "xxx"));
nameValuePairs.add(new BasicNameValuePair("geotable_id", "153944"));
nameValuePairs.add(new BasicNameValuePair("title", "xxx"));
nameValuePairs.add(new BasicNameValuePair("address", "xxx"));
nameValuePairs.add(new BasicNameValuePair("latitude", "xxx.xxx"));
nameValuePairs.add(new BasicNameValuePair("longitude", "xxx.xxx"));
nameValuePairs.add(new BasicNameValuePair("coord_type", "3"));
nameValuePairs.add(new BasicNameValuePair("ak", "xxxxxxx"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
}
二、HttpClient --- 百度地图LBS云检索
public class BaiduMapCloudSearchTest {
@Test
// 周边检索
public void demo1() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geosearch/v3/nearby?ak=xxxxx&geotable_id=153944&location=xxx.xxx,xxx.xxx&radius=1000");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 本地检索
public void demo2() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geosearch/v3/local?region=xxx&ak=xxxxxx&geotable_id=153944&location=xxx.xxx,xxx.xxx&radius=1000");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 云地理编码
public void demo3() throws IOException {
String address = URLEncoder.encode("xxx", "utf-8");
String url = "http://api.map.baidu.com/cloudgc/v1?geotable_id=153944&ak=xxxxxx&address="
+ address;
System.out.println(url);
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
}
三、HttpClient --- 百度地图LBS路线
public class BaiduMapWebServiceTest {
@Test
public void demo1() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/place/v2/suggestion?ak=xxxxxx®ion=xx&q=xx&output=json");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 地理编码 api
public void demo2() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
String address = URLEncoder.encode("xxxxxx", "utf-8");
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geocoder/v2/?ak=xxxxxx&output=json&address="
+ address);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 路线规划距离和行驶时间
public void demo3() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/routematrix/v2/riding?ak=xxxxxx&output=json&origins=xxx.xxx,xxx.xxx&destinations=xxx.xxx,xxx.xxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 路线规划
public void demo4() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/direction/v2/transit?ak=xxxxxx&output=json&origin=xxx.xxx,xxx.xxx&destination=xxx.xxx,xxx.xxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// ip高精度定位
public void demo5() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/highacciploc/v1?ak=xxxxxx&qterm=pc&callback_type=json&coord=bd09ll");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test
// 转换坐标
public void demo6() throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://api.map.baidu.com/geoconv/v1/?ak=xxxxxx&output=json&coords=xxx.xxx,xxx.xxx");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
}