|
|
@@ -0,0 +1,30 @@
|
|
|
+package work.baiyun.chronicdiseaseapp.controller;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+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;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import work.baiyun.chronicdiseaseapp.common.R;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/geo")
|
|
|
+public class GeoController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @GetMapping("/nearest")
|
|
|
+ public R<String> getNearestGeo(@RequestParam double latitude, @RequestParam double longitude) throws work.baiyun.chronicdiseaseapp.exception.CustomException {
|
|
|
+ try {
|
|
|
+ String url = "http://45.207.222.6/geo/nearest.php?latitude=" + latitude + "&longitude=" + longitude;
|
|
|
+ ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
|
|
+ return R.success(200, "ok", response.getBody());
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 异常由全局处理器处理,这里抛出 CustomException 或直接返回 fail
|
|
|
+ throw new work.baiyun.chronicdiseaseapp.exception.CustomException("地理编码请求失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|