1.1 LBS云服务 (百度提供的数据库)
LBS.云是百度地图针对LBS开发者推出的平台级服务,结合已有的地图API和SDK服务,通过开放服务端存储和计算能力,提供海量位置数据(点、面数据)的实时存储、检索、展示一体化解决方案。1. 创建AK
一定要使用服务端的密钥,只有服务端才支持云存储
2. 使用HttpClient发送http的请求
/* * LBS创建表 */ @Test publicvoid createTable() throwsClientProtocolException, IOException { HttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v4/geotable/create"); List<NameValuePair>nameValuePairs = newArrayList<NameValuePair>(); nameValuePairs.add(newBasicNameValuePair("name", "Test")); nameValuePairs.add(newBasicNameValuePair("is_published", "1")); nameValuePairs.add(newBasicNameValuePair("ak", "ZAZXk1fxXphtggZhvlpiV4Gbnmf45610")); httpPost.setEntity(newUrlEncodedFormEntity(nameValuePairs)); HttpResponse httpResponse= httpClient.execute(httpPost); System.out.println(EntityUtils.toString(httpResponse.getEntity())); } /* * LBS插入数据 */ @Test publicvoid insertData() throwsClientProtocolException, IOException { HttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v4/poi/create"); List<NameValuePair>nameValuePairs = newArrayList<NameValuePair>(); nameValuePairs.add(newBasicNameValuePair("title", "南京中心")); nameValuePairs.add(newBasicNameValuePair("address", "鼓楼高楼门5号")); nameValuePairs.add(newBasicNameValuePair("latitude", "32.066403")); nameValuePairs.add(newBasicNameValuePair("longitude", "118.792749")); nameValuePairs.add(newBasicNameValuePair("coord_type", "3")); nameValuePairs.add(newBasicNameValuePair("geotable_id", "1000003746")); nameValuePairs.add(newBasicNameValuePair("ak", "ZAZXk1fxXphtggZhvlpiV4Gbnmf45610")); httpPost.setEntity(newUrlEncodedFormEntity(nameValuePairs,Charsets.UTF_8)); HttpResponse httpResponse= httpClient.execute(httpPost); System.out.println(EntityUtils.toString(httpResponse.getEntity())); } /* * LBS查询数据 */ @Test publicvoid selectData() throwsClientProtocolException, IOException { HttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost("http://api.map.baidu.com/geodata/v4/poi/list"); List<NameValuePair>nameValuePairs = newArrayList<NameValuePair>(); nameValuePairs.add(newBasicNameValuePair("coord_type", "3")); nameValuePairs.add(newBasicNameValuePair("geotable_id", "1000003746")); nameValuePairs.add(newBasicNameValuePair("ak", "ZAZXk1fxXphtggZhvlpiV4Gbnmf45610")); httpPost.setEntity(newUrlEncodedFormEntity(nameValuePairs,Charsets.UTF_8)); HttpResponse httpResponse= httpClient.execute(httpPost); System.out.println(EntityUtils.toString(httpResponse.getEntity())); }