wlzboy
5 天以前 7de1396e315896dbc72a9d54e44f77434ea90f18
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
package com.ruoyi.web.controller.system;
 
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.dto.GeocodeResult;
import com.ruoyi.system.service.IGeocodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * 地理编码控制器
 */
@RestController
@RequestMapping("/system/geocode")
public class GeocodeController extends BaseController {
 
    @Autowired
    private IGeocodeService geocodeService;
 
    /**
     * 根据地址获取GPS坐标
     * 
     * @param address 地址字符串
     * @param city 城市名称(可选),用于提高解析准确度
     * @return 地理编码结果
     */
    @GetMapping("/address")
    public AjaxResult getCoordinatesByAddress(
            @RequestParam("address") String address,
            @RequestParam(value = "city", required = false) String city) {
        
        GeocodeResult result = geocodeService.getCoordinatesByAddress(address, city);
        
        if (result.getSuccess()) {
            return AjaxResult.success("地理编码成功", result);
        } else {
            return AjaxResult.error(result.getErrorMessage());
        }
    }
}