SpringBoot接入高德地图猎鹰轨迹服务API
一、AP文档
二、页面图
1、需登录账号,申请对应的应用key值
三、代码部分:
1、控制层
@RestController
@RequestMapping("/gdTrack")
public class TrackController {
private final MapTrackUtils mapTrackUtils;
public TrackController(MapTrackUtils mapTrackUtils) {
this.mapTrackUtils = mapTrackUtils;
}
/**
* 创建轨迹服务
* @param serviceName 轨迹服务名称
* @return 轨迹服务创建响应
*/
@ApiOperation("/创建服务")
@PostMapping("/createTrackService")
public String createTrackService(@RequestParam String serviceName) {
return mapTrackUtils.createTrackService(serviceName);
}
/**
* 更新轨迹服务
* @return 轨迹更新响应
*/
@ApiOperation("/更新服务")
@PostMapping("/updateTrack")
public String updateTrack(@RequestParam String sid, @RequestParam String name) {
return mapTrackUtils.updateTrack(sid, name);
}
/**
* 查询轨迹服务
* @return 查询服务
*/
@ApiOperation("/查询服务")
@GetMapping("/queryTrackList")
public String queryTrackList() {
return mapTrackUtils.queryTrackList();
}
/**
* 查询轨迹服务
* @return 查询服务
*/
@ApiOperation("/删除服务")
@GetMapping("/delServiceName")
public String delServiceName(@RequestParam String sid) {
return mapTrackUtils.delServiceName(sid);
}
/**
* @return 创建终端
*/
@ApiOperation("/创建终端")
@GetMapping("/createTerminal")
public String createTerminal(@RequestParam String sid,@RequestParam String name) {
return mapTrackUtils.createTerminal(sid,name);
}
/**
* @return 查询终端
*/
@ApiOperation("/查询终端")
@GetMapping("/seeTerminal")
public String seeTerminal(@RequestParam String sid) {
return mapTrackUtils.seeTerminal(sid);
}
/**
* @return 创建轨迹
*/
@ApiOperation("/创建轨迹")
@GetMapping("/createTrace")
public String createTrace(@RequestParam String sid,@RequestParam String tid) {
return mapTrackUtils.createTrace(sid,tid);
}
/**
* @return 查询轨迹
*/
@ApiOperation("/查询轨迹")
@GetMapping("/seeTrace")
public String seeTrace(@RequestParam String sid,
@RequestParam String tid,
@RequestParam(name = "trid",required = false) String trid,
@RequestParam(name = "starttime",required = false) String starttime,
@RequestParam(name = "endtime",required = false) String endtime) {
return mapTrackUtils.seeTrace(sid,tid,trid,starttime,endtime);
}
}
2、OcrBdUtils工具类
@Component
public class MapTrackUtils {
/**鹰眼*/
public static final String API_KEY = "替换自己申请的key";
private final RestTemplate restTemplate;
public MapTrackUtils(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
/**
* 创建轨迹服务
* @param serviceName 轨迹服务名称
* @return 轨迹服务创建的响应
*/
public String createTrackService(String serviceName) {
String url = "https://tsapi.amap.com/v1/track/service/add?key=" + API_KEY + "&name=" + serviceName;
JSONObject jsonObject = new JSONObject();
jsonObject.put("name",serviceName);
return restTemplate.postForObject(url, "", String.class);
}
/**
* 更新轨迹服务https://tsapi.amap.com/v1/track/service/update
* @return 更新轨迹的响应
*/
public String updateTrack(String sid, String name) {
String url = "https://tsapi.amap.com/v1/track/service/update?key=" + API_KEY + "&name=" + name + "&sid=" + sid;
return restTemplate.postForObject(url, "", String.class);
}
/**
* 查看轨迹服务
* @return
*/
public String queryTrackList() {
String url = "https://tsapi.amap.com/v1/track/service/list?key=" + API_KEY;
return restTemplate.getForObject(url, String.class);
}
/**
* 删除服务
* @param sid
* @return
*/
public String delServiceName(String sid) {
String url = "https://tsapi.amap.com/v1/track/service/delete?key=" + API_KEY + "&sid=" + sid;
return restTemplate.postForObject(url,"", String.class);
}
/**
* 创建终端
* @param sid
* @param name
* @return
*/
public String createTerminal(String sid, String name) {
String url = "https://tsapi.amap.com/v1/track/terminal/add?key=" + API_KEY + "&sid=" + sid + "&name=" + name;
return restTemplate.postForObject(url,"", String.class);
}
/**
* 查看终端
* @param sid
* @return
*/
public String seeTerminal(String sid) {
String url = "https://tsapi.amap.com/v1/track/terminal/list?key=" + API_KEY + "&sid=" + sid;
return restTemplate.getForObject(url, String.class);
}
/**
* 创建轨迹
* @param sid
* @param tid
* @return
*/
public String createTrace(String sid, String tid) {
String url = "https://tsapi.amap.com/v1/track/trace/add?key=" + API_KEY + "&sid=" + sid + "&tid=" + tid;
return restTemplate.postForObject(url,"", String.class);
}
/**
* 查看轨迹
* @param sid
* @param tid
* @param trid
* @param starttime
* @param endtime
* @return
*/
public String seeTrace(String sid, String tid, String trid, String starttime, String endtime) {
String url = "";
if(!"".equals(trid) && null != trid ){
url = "https://tsapi.amap.com/v1/track/terminal/trsearch?key=" + API_KEY + "&sid=" + sid +
"&tid=" + tid + "&trid=" + trid;
}else {
url = "https://tsapi.amap.com/v1/track/terminal/trsearch?key=" + API_KEY + "&sid=" + sid + "&tid=" +tid +
"&starttime=" + starttime + "&endtime=" + endtime;
}
return restTemplate.getForObject(url, String.class);
}
}
一个在学习中的开发者,勿喷,欢迎交流