高德接口对接

/ 2025-12-22

@Slf4j
@Component
public class AmapUtil {

  1. private static AmapUtil instance;
  2. @Value("${amap.key}")
  3. private String KEY;
  4. @Value("${amap.geo-url}")
  5. private String GEO_URL;
  6. @PostConstruct
  7. public void init() {
  8. instance = this;
  9. }
  10. /**
  11. * 高德接口用于位置补全
  12. * @param address
  13. * @return
  14. */
  15. public static GeoResponse getGeoList(String address) {
  16. if (StringUtils.isBlank(address)) {
  17. log.warn("address为空!!!");
  18. return new GeoResponse();
  19. }
  20. try {
  21. String paramStr = "address=" + URLEncoder.encode(address, "UTF-8");
  22. String reqUri = instance.GEO_URL.concat("?key=").concat(instance.KEY).concat("&").concat(paramStr);
  23. HttpResponse response = HttpRequest.get(reqUri).execute();
  24. return JSON.parseObject(response.body(), GeoResponse.class);
  25. } catch (Exception e) {
  26. log.error("调用高德接口异常,address={}", address, e);
  27. return new GeoResponse();
  28. }
  29. }

}


转载请注明作者和出处,并添加本页链接。
原文链接: //pongpongkai.top/170

皖ICP备2025092356号-1 | 沪公网安备31011202021249号