百度提供的LBS服务
并不是所有 LBS 云服务 都可以使用 js Ajax 访问,涉及跨域问题 (Jsonp 方式解决)Jsonp 解决跨域问题原理,在页面生成<script> 加载远程 js 代码片段.在LBS的服务文档:http://lbsyun.baidu.com/index.php?title=lbscloud/api/geosearch,除了云存储都有callback回调函数.在jQuery的API文档中 $.getJSON(url,[data],function(data))加入callback=?执行回调函数.
package cn.itcast.map;import java.io.IOException; import java.util.ArrayList; import java.util.List;import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.junit.Test;// 云存储 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", "zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf"));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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf");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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf");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", "zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf"));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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf");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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf");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", "zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf"));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", "好嫂子")); nameValuePairs.add(new BasicNameValuePair("address", "海淀区建材城西路xx号")); nameValuePairs.add(new BasicNameValuePair("latitude", "39.899552")); nameValuePairs.add(new BasicNameValuePair("longitude", "116.647367")); nameValuePairs.add(new BasicNameValuePair("coord_type", "3")); nameValuePairs.add(new BasicNameValuePair("ak", "zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf"));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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf");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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf");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", "1822675338")); nameValuePairs.add(new BasicNameValuePair("geotable_id", "153944")); nameValuePairs.add(new BasicNameValuePair("title", "好嫂子")); nameValuePairs.add(new BasicNameValuePair("address", "海淀区建材城西路xx号")); nameValuePairs.add(new BasicNameValuePair("latitude", "40.066269")); nameValuePairs.add(new BasicNameValuePair("longitude", "116.353776")); nameValuePairs.add(new BasicNameValuePair("coord_type", "3")); nameValuePairs.add(new BasicNameValuePair("ak", "zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf"));httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); System.out.println(EntityUtils.toString(httpEntity)); }@Test public void demoX() { System.out.println("\u53c2\u6570\u5fc5\u9700"); } }
2.BaiduMapCloudSearch
package cn.itcast.map;import java.io.IOException; import java.net.URLEncoder;import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.junit.Test;// 云检索 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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&geotable_id=153944&location=116.647367,39.899552&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=北京&ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&geotable_id=153944&location=116.647367,39.899552&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("好嫂子", "utf-8");String url = "http://api.map.baidu.com/cloudgc/v1?geotable_id=153944&ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&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));} }
3.BaiduMapWebServiceTest
package cn.itcast.map;import java.io.IOException; import java.net.URLEncoder;import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.junit.Test;// web开放服务 public class BaiduMapWebServiceTest {@Test// Place Suggestion APIpublic void demo1() throws IOException {HttpClient httpClient = HttpClients.createDefault();HttpGet httpGet = new HttpGet("http://api.map.baidu.com/place/v2/suggestion?ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf®ion=全国&q=和平&output=json");HttpResponse httpResponse = httpClient.execute(httpGet);HttpEntity httpEntity = httpResponse.getEntity();System.out.println(EntityUtils.toString(httpEntity));}@Test// 地理编码 apipublic void demo2() throws IOException {HttpClient httpClient = HttpClients.createDefault();String address = URLEncoder.encode("北京市海淀区上地十街10号", "utf-8");HttpGet httpGet = new HttpGet("http://api.map.baidu.com/geocoder/v2/?ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&output=json&origins=40.056878,116.30815&destinations=40.063597,116.364973");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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&output=json&origin=40.056878,116.30815&destination=40.063597,116.364973");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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&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=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&output=json&coords=114.21892734521,29.575429778924");HttpResponse httpResponse = httpClient.execute(httpGet);HttpEntity httpEntity = httpResponse.getEntity();System.out.println(EntityUtils.toString(httpEntity));} }
4.周边检索( 基于 JavaScript 访问 LBS 云服务)
<!DOCTYPE html> <html><head><meta charset="UTF-8"><title>周边检索 </title><script type="text/javascript" src="js/jquery.js" ></script><script type="text/javascript">$.getJSON("http://api.map.baidu.com/geosearch/v3/nearby?ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&geotable_id=153944&q=好嫂子&location=116.395884,39.932154&radius=5000&callback=?",function(data){console.log(data);});</script></head><body></body> </html>
5.本地检索( 基于 JavaScript 访问 LBS 云服务)
<!DOCTYPE html> <html><head><meta charset="UTF-8"><title>本地检索 </title><script type="text/javascript" src="js/jquery.js" ></script><script type="text/javascript">$.getJSON("http://api.map.baidu.com/geosearch/v3/local?ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&geotable_id=153944&q=好嫂子®ion=北京市&callback=?",function(data){console.log(data);});</script></head><body></body> </html>
6.云地理检索 ( 基于 JavaScript 访问 LBS 云服务)
<!DOCTYPE html> <html><head><meta charset="UTF-8"><title>云地理编码</title><script type="text/javascript" src="js/jquery.js" ></script><script type="text/javascript">var address = encodeURIComponent("金燕龙办公楼");$.getJSON("http://api.map.baidu.com/cloudgc/v1?ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf&address="+address+"&callback=?",function(data){console.log(data);});</script></head><body></body> </html>
转载于:https://www.cnblogs.com/wwwzzz/p/8109424.html
百度提供的LBS服务相关推荐
- Android 高仿百度地图的LBS服务——基础地图篇(v 3.1.1)
一.前言 转载请标明出处:http://blog.csdn.net/wlwlwlwl015/article/details/41076537 因为项目需要集成地图功能,所以交给我负责研究并继续完善百度 ...
- Android 高仿百度地图的LBS服务——离线地图篇 Part 2 (v 3.1.1)
一.前言 转载请标明出处:http://blog.csdn.net/wlwlwlwl015/article/details/41492031 这一篇blog写的真心不容易,我只想说我这种菜鸟去高仿百度 ...
- 百度LBS服务我们自己上传数据,我们客户端获取数据然后进行小黄车和膜拜单车定位描点等骚操作
一,演示和需求的SDK和ak等配置最近我们一个项目需要自己android端上传数据到百度LBS服务,然后获取数据并显示.搞了2天完成了.其实很简单的哦!我们一步步来,今天的活我一小时搞定,一天写博客, ...
- 百度云加速为哪些行业提供专业的服务?
精准的业务场景+全网数据分析,定制行业专属服务. 1.游戏云:全域布局的节点为满足游戏用户的高速低延迟需求提供保障,提供安全高效的加速服务和标准化.可视化的游戏运维服务. 2.医疗云:结合百度云加速平 ...
- 免费提供AI开发服务、开放百节AI课程 ,百度大脑与开发者携手“战疫”
面对新冠肺炎疫情,AI 开发者们正在积极运用算法.算力.软件等"武器"助力抗疫.针对开发者们在疫情防控期间的开发与学习需求,2月6日,百度大脑推出"AI 开发者战疫守护计 ...
- 百度大脑发布企业服务解决方案,将 AI 技术落实到细分领域
人工智能竞争之势愈演愈烈,AI与场景应用的深度结合将成为各家企业的取胜关键.10月18日,百度大脑行业创新论坛在北京正式拉开帷幕,届时将走进全国6个城市举办7场以企业服务.信息服务和零售等为主题的专题 ...
- 半个月两次投资,百度健康再扩服务版图
文|螳螂财经(TanglangFin) 作者|陈壹 以互联网+医疗为趋势的变革正在成为我国创新医疗服务模式的新特征.据中商产业研究院的数据显示,中国互联网医疗市场由2016年的650亿元增至2020年 ...
- 百度Create2021:百度地图日均位置服务请求次数突破1300亿
12月27日,百度Create 2021(百度AI开发者大会)举行,在智能地图论坛上,百度地图智能物流.智能空间.智慧文旅等多个行业解决方案集中亮相,展示了百度地图在各行各业智能化升级中的支撑作用. ...
- 游戏账号交易平台,是专门为网络游戏提供相关交易服务的电子商务平台,主要从事网络游戏账号的交易。
JAVA语言开发.VUE开发前端技术.支持SEO百度爬虫检索. 账号交易平台,支持分站.加价,商户入驻等功能. 游戏账号交易平台,是专门为网络游戏提供相关交易服务的电子商务平台,主要从事网络游戏账号的 ...
最新文章
- Python中的类、模块和包究竟是什么?
- 介绍一些简单实用的Python小tricks
- 如何合理的学习Netty?(学习目录)
- 数据库索引类型及实现方式
- 基于SSM实现的奶茶店会员管理系统
- Selenium2学习(八)-- 操作元素(键盘和鼠标事件)
- python编程实例详解-Python编程之列表操作实例详解【创建、使用、更新、删除】...
- python数据分析入门学习笔记儿
- java udp 缓冲区_为什么特定的UDP消息总是低于特定的缓冲区大小?
- WebRTC安全体系架构的8个组件
- ENVI扩展工具:利用波段运算修改NaN方法总结
- 【BZOJ】1649: [Usaco2006 Dec]Cow Roller Coaster(dp)
- Xshell代理访问外网或者公司的内网
- 使用Tensorflow Lite创建一个Android AI应用
- NeurIPS 2019:进入NLP的黄金时代
- Unity PID 控制算法可视化学习
- Hadoop之HDFS的回收站
- 农历大小月的确定方法
- python一行输入n个数据
- 仓鼠找sugar II