百度地图api通过经纬度获取地理位置
This commit is contained in:
parent
7226dab94d
commit
fbf16fab0e
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.ghy.web.controller.tool;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ghy.common.config.BaiduConfig;
|
||||||
|
import com.ghy.common.core.controller.BaseController;
|
||||||
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import com.ghy.common.utils.ExceptionUtil;
|
||||||
|
import com.ghy.common.utils.http.HttpUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/tool/baidu")
|
||||||
|
public class BaiduController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BaiduConfig baiduConfig;
|
||||||
|
|
||||||
|
@PostMapping("/getLocation")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult getLocationByLot(String location){
|
||||||
|
try {
|
||||||
|
String url = baiduConfig.getUrl().replace("#AK#", baiduConfig.getAk()) + location;
|
||||||
|
String result = HttpUtils.sendGet(url);
|
||||||
|
return AjaxResult.success(result);
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -125,3 +125,8 @@ jim:
|
||||||
appKey: ''
|
appKey: ''
|
||||||
masterSecret: ''
|
masterSecret: ''
|
||||||
maxRetryTimes: ''
|
maxRetryTimes: ''
|
||||||
|
|
||||||
|
# 百度地图应用api
|
||||||
|
baidu:
|
||||||
|
ak: 'ZQTgMW7W0GTuE7Ripb0HDp5TqRaOI6PZ'
|
||||||
|
url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=#AK#&output=json&coordtype=wgs84ll&location='
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.ghy.common.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 百度地图应用ak配置
|
||||||
|
* @author clunt
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "baidu")
|
||||||
|
public class BaiduConfig {
|
||||||
|
|
||||||
|
private String ak;
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
public String getAk() {
|
||||||
|
return ak;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAk(String ak) {
|
||||||
|
this.ak = ak;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue