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()); } }