高德智能穿戴设备定位sdk接入
一、准备工作:
- 申请一个企业的账号(必须是企业的账号)
-
【高德智能穿戴设备定位sdk接入】
申请key:
文章图片
image.png -
获取开发文档:
文章图片
image.png
高德地图支持wifi、基站定位
- wifi定位:
/**
* @author ww
* @version 1.0
* @Date 2020/1/6
*/
@RestController
public class PositionController {/**
*
*/
static class Constants {/**
*
*/
public static final String QUESTION_MARK = "?";
/**
*
*/
public static final String EQUALS = "=";
/**
*
*/
public static final String AND = "&";
/**
*
*/
public static final String CHARSET = "UTF-8";
/**
* url
*/
private static final String BASE_URL = "https://apilocate.amap.com/position";
}/**
* 高德wifi 定位
* @return
*/
@RequestMapping(value = "https://www.it610.com/position")
public String position() {
Map params = new HashMap<>();
// wifi定位参数
params.put("macs", "4c:48:da:25:0b:11,-59,alibaba-inc%7c4c:48:da:25:1a:11,-77,alibaba-inc");
// 是否为移动网 0 表示移动网 1表示是wifi
params.put("accesstype", "1");
// 申请的api的key
params.put("key", "修改成申请的api key");
// 输出内容为json字符串
params.put("output", "json");
StringBuilder sb = new StringBuilder();
sb.append(Constants.BASE_URL);
if (!CollectionUtils.isEmpty(params)) {
sb.append(Constants.QUESTION_MARK);
for (Map.Entry entry : params.entrySet()) {
sb.append(entry.getKey()).append(Constants.EQUALS).append(entry.getValue()).append(Constants.AND);
}
sb.deleteCharAt(sb.length() - 1);
}
// 请求定位sdk
HttpGet get = new HttpGet(sb.toString());
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
HttpEntity entity;
try {
httpClient = HttpClients.createDefault();
response = httpClient.execute(get);
entity = response.getEntity();
return EntityUtils.toString(entity, Constants.CHARSET);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
注意问题:
- 包含多个macs的列表的时候高德给的sdk里面有一个特殊字符"|",这个字符用httpclient请求定位的sdk的时候,会报错如:
java.net.URISyntaxException: Illegal character in query at index 97。此时需要将"|" 更换成%7c(%加上16进制的该字符的ASCII值)
推荐阅读
- 人工智能|干货!人体姿态估计与运动预测
- 从前沿科技到现实应用,人脸识别智能门禁加速走进智慧社区
- 众泰T500智能互联双加载,让汽车生活更有趣
- 历史上的今天|【历史上的今天】2 月 16 日(世界上第一个 BBS 诞生;中国计算机教育开端;IBM 机器人赢得智能竞赛)
- 【兔兔*亲子】八大智能启蒙之第三周记录
- 基于stm32智能风扇|基于stm32智能风扇_一款基于STM32的智能灭火机器人设计
- stm32|基于STM32和freeRTOS智能门锁设计方案
- 浅析(成人情趣用品智能无人自动售货机是新零售的下一个风口吗())
- Android智能手表MMI测试检测系统
- 【乐高创意作品】超智能!这款乐高搭建的除草机!