[英]How to use SSL Certificates in Spring Boot application to call remote API
[英]How To use DistanceMatrix Api in Spring boot Application
我需要使用 DestanceMatrix API 来计算起点到终点之间的距离。
谁能帮我在 spring 引导应用程序中实现此功能?
提前致谢...
public static void distanceMatrixTest() {
GeoApiContext context = new GeoApiContext.Builder().apiKey(GOOGLE_API_KEY_STATIC).build();
DistanceMatrixRow[] rows = DistanceMatrixApi.newRequest(context)
.origins(new LatLng(3.1054104954261823, 101.39172498261695))
.destinations(new LatLng(3.0651174019721434, 101.79107501515256),
new LatLng(3.0362824146932934, 101.75871771663888),
new LatLng(3.0717816850989803, 101.75618972318607))
.awaitIgnoreError().rows;
if (rows.length != 0) {
for (int i = 0; i < rows.length; i++) {
for (int j = 0; j < rows[i].elements.length; j++) {
System.out.println("Distance for j === " + j + " - " + rows[i].elements[j].distance.humanReadable);
System.out.println("Distance for j === " + j + " - " + rows[i].elements[j].distance.inMeters);
System.out.println("-----------------------------------------");
System.out.println("Duration for j === " + j + " - " + rows[i].elements[j].duration.humanReadable);
System.out.println("Duration for j === " + j + " - " + rows[i].elements[j].duration.inSeconds);
System.out.println("Status for j === " + j + " - " + rows[i].elements[j].status);
System.out.println("------------ NEXT Record ----------------");
}
}
}
// Invoke .shutdown() after your application is done making requests
context.shutdown();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.