nickchange
2023-12-05 9f66f1772e9a2499c030d89479242457b5f9aafd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.stylefeng.guns.modular.system.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.modular.system.util.httpClinet.HttpClientUtil;
import com.stylefeng.guns.modular.system.util.httpClinet.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
/**
* 腾讯地图api工具类型
* @author pzb
* @Date 2021/12/27 11:37
*/
@Component
public class TencentMapUtil {
 
    private final String key = "";
 
    @Autowired
    private HttpClientUtil httpClientUtil;
 
 
    /**
     * 坐标转换
     * @param locations 纬度前,经度后,纬度和经度之间用",“分隔,每组坐标之间使用”;"分隔;
     * @param type      1 GPS坐标 2 sogou经纬度 3 baidu经纬度 4 mapbar经纬度 5 [默认]腾讯、google、高德坐标 6 sogou墨卡托
     * @return
     */
    public ResultUtil translate(String locations, Integer type) throws Exception{
        String url = "https://apis.map.qq.com/ws/coord/v1/translate?locations=" + locations + "&type=" + type + "&key=" + key;
        HttpResult httpResult = httpClientUtil.pushHttpRequset("GET", url, null, null, "json");
        if(httpResult.getCode() == 200){
            JSONObject jsonObject = JSON.parseObject(httpResult.getData());
            if(jsonObject.getInteger("status") == 0){
                JSONObject locations1 = jsonObject.getJSONArray("locations").getJSONObject(0);
                return ResultUtil.success(locations1.getString("lng") + "," + locations1.getString("lat"));
            }else{
                return ResultUtil.error(jsonObject.getString("message"));
            }
        }
        return ResultUtil.error(httpResult.getData());
    }
}