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