百度地图api通过经纬度获取地理位置

This commit is contained in:
kuang.yifei@iwhalecloud.com 2022-07-20 14:42:35 +08:00
parent fbf16fab0e
commit b92c77d64a
1 changed files with 5 additions and 1 deletions

View File

@ -1,14 +1,17 @@
package com.ghy.web.controller.tool; package com.ghy.web.controller.tool;
import com.alibaba.fastjson.JSONObject;
import com.ghy.common.config.BaiduConfig; import com.ghy.common.config.BaiduConfig;
import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.ExceptionUtil; import com.ghy.common.utils.ExceptionUtil;
import com.ghy.common.utils.http.HttpUtils; import com.ghy.common.utils.http.HttpUtils;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@ -21,8 +24,9 @@ public class BaiduController extends BaseController {
@PostMapping("/getLocation") @PostMapping("/getLocation")
@ResponseBody @ResponseBody
public AjaxResult getLocationByLot(String location){ public AjaxResult getLocationByLot(@RequestBody JSONObject jsonObject){
try { try {
String location = jsonObject.getString("location");
String url = baiduConfig.getUrl().replace("#AK#", baiduConfig.getAk()) + location; String url = baiduConfig.getUrl().replace("#AK#", baiduConfig.getAk()) + location;
String result = HttpUtils.sendGet(url); String result = HttpUtils.sendGet(url);
return AjaxResult.success(result); return AjaxResult.success(result);