xuhy
2025-06-16 0efe6213bfdd3281f73d91579b50b88e4ec8cb49
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
package com.ruoyi.web.util;
 
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
 
import java.io.IOException;
 
public class AmapApiClient {
    private static final String KEY = "e700a58329a38b2d8980790d9b1b5b06";
    private static final OkHttpClient client = new OkHttpClient();
 
    public static String getDrivingRoute(double startLat, double startLon, double endLat, double endLon) throws IOException {
        String url = "https://restapi.amap.com/v3/direction/walking?" +
                "origin=" + startLon + "," + startLat +
                "&destination=" + endLon + "," + endLat +
                "&key=" + KEY;
 
        Request request = new Request.Builder()
                .url(url)
                .build();
 
        try (Response response = client.newCall(request).execute()) {
            return response.body().string();
        }
    }
}