ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package jnpf.base.controller;
 
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.model.province.MapParams;
import jnpf.constant.MsgCode;
import jnpf.util.NoDataSourceBind;
import jnpf.util.ServletUtil;
import jnpf.util.wxutil.HttpUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.imageio.ImageIO;
import jakarta.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
 
@Tag(name = "定位转发接口", description = "location")
@RestController
@RequestMapping("/Location")
public class LocationController {
 
    @Operation(summary = "查询附近数据")
    @GetMapping("/around")
    @NoDataSourceBind
    public ActionResult<JSONObject> getAroundList(MapParams params) {
        JSONObject rstObj;
        String url = "https://restapi.amap.com/v3/place/around?key=" + params.getKey() + "&location=" + params.getLocation()
                + "&radius=" + params.getRadius() + "&offset=" + params.getOffset() + "&page=" + params.getPage();
        try {
            rstObj = HttpUtil.httpRequest(url, "GET", null);
        } catch (Exception e) {
            return ActionResult.fail(MsgCode.SYS023.get());
        }
        if (rstObj == null) {
            return ActionResult.fail(MsgCode.SYS024.get());
        }
        return ActionResult.success(rstObj);
    }
 
    @Operation(summary = "根据关键字查询附近数据")
    @GetMapping("/text")
    @NoDataSourceBind
    public ActionResult<JSONObject> getTextList(MapParams params) {
        JSONObject rstObj;
        String url = "https://restapi.amap.com/v3/place/text?key=" + params.getKey() + "&keywords=" + params.getKeywords()
                + "&radius=" + params.getRadius() + "&offset=" + params.getOffset() + "&page=" + params.getPage();
        try {
            rstObj = HttpUtil.httpRequest(url, "GET", null);
        } catch (Exception e) {
            return ActionResult.fail(MsgCode.SYS023.get());
        }
        if (rstObj == null) {
            return ActionResult.fail(MsgCode.SYS024.get());
        }
        return ActionResult.success(rstObj);
    }
 
    @Operation(summary = "输入提示")
    @GetMapping("/inputtips")
    @NoDataSourceBind
    public ActionResult<JSONObject> getInputTips(MapParams params) {
        JSONObject rstObj;
        String url = "https://restapi.amap.com/v3/assistant/inputtips?key=" + params.getKey() + "&keywords=" + params.getKeywords();
        try {
            rstObj = HttpUtil.httpRequest(url, "GET", null);
        } catch (Exception e) {
            return ActionResult.fail(MsgCode.SYS023.get());
        }
        if (rstObj == null) {
            return ActionResult.fail(MsgCode.SYS024.get());
        }
        return ActionResult.success(rstObj);
    }
 
    @Operation(summary = "定位图片")
    @GetMapping("/staticmap")
    @NoDataSourceBind
    public void staticmap(MapParams params) {
        String requestUrl = "https://restapi.amap.com/v3/staticmap?location=" + params.getLocation() + "&zoom=" + params.getZoom() + "&size="
                + params.getSize() + "&key=" + params.getKey();
        try {
            URL url = new URL(requestUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(50000);
            conn.setReadTimeout(60000);
            conn.setRequestProperty("Content-Type", "image/png");
            InputStream ins = null;
            OutputStream os = null;
            try {
                ins = conn.getInputStream();
                HttpServletResponse response = ServletUtil.getResponse();
                BufferedImage image = ImageIO.read(ins);
                os = response.getOutputStream();
                if (image != null) {
                    ImageIO.write(image, "png", os);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                conn.disconnect();
                os.flush();
                os.close();
                ins.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @Operation(summary = "经纬度转地址")
    @GetMapping("/regeo")
    @NoDataSourceBind
    public ActionResult<JSONObject> regeo(MapParams params) {
        JSONObject rstObj;
        String url = "https://restapi.amap.com/v3/geocode/regeo?key=" + params.getKey() + "&&location=" + params.getLocation();
        try {
            rstObj = HttpUtil.httpRequest(url, "GET", null);
        } catch (Exception e) {
            return ActionResult.fail(MsgCode.SYS023.get());
        }
        if (rstObj == null) {
            return ActionResult.fail(MsgCode.SYS024.get());
        }
        return ActionResult.success(rstObj);
    }
}