Pu Zhibing
7 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/GoogleMap/GoogleMapUtil.java
@@ -5,13 +5,14 @@
import com.google.gson.GsonBuilder;
import com.google.maps.*;
import com.google.maps.model.*;
import com.stylefeng.guns.core.util.ToolUtil;
/**
 * 谷歌地图工具类
 */
public class GoogleMapUtil {
    private final static String key = "AIzaSyA_FEliOkbkL1IAHQsnBpbpo9MlIp729H0";
    private final static String key = "AIzaSyCG6PsfkaCEc94VK2vIAZk1YYKvOS_Ewts";
    /**
@@ -49,12 +50,15 @@
     * @return
     * @throws Exception
     */
    public static ReverseGeocodeVo getReverseGeocode(double lat, double lng) throws Exception{
    public static ReverseGeocodeVo getReverseGeocode(double lat, double lng, String tripId) throws Exception{
        GeoApiContext context = new GeoApiContext.Builder()
                .apiKey(key)
                .build();
        GeocodingApiRequest request = GeocodingApi.reverseGeocode(context, new LatLng(lat, lng));
        request.language("en");
        if(ToolUtil.isNotEmpty(tripId)){
            request.header("X-Goog-Maps-Experience-ID", tripId);//行程id
        }
        GeocodingResult[] results = request.await();
        ReverseGeocodeVo vo = null;
        if(results.length > 0){
@@ -162,13 +166,16 @@
     * @return
     * @throws Exception
     */
    public static DistancematrixVo getDistancematrix(String origin, String destination) throws Exception{
    public static DistancematrixVo getDistancematrix(String origin, String destination, String tripId) throws Exception{
        GeoApiContext context = new GeoApiContext.Builder()
                .apiKey(key)
                .build();
        DistanceMatrixApiRequest request = DistanceMatrixApi.getDistanceMatrix(context, new String[]{origin}, new String[]{destination});
        request.language("en");
        request.mode(TravelMode.DRIVING);//出行方式(驾车)
        if(ToolUtil.isNotEmpty(tripId)){
            request.header("X-Goog-Maps-Experience-ID", tripId);//行程id
        }
        DistanceMatrix distanceMatrix = request.await();
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        System.err.println(gson.toJson(distanceMatrix));
@@ -197,7 +204,7 @@
     * @return
     * @throws Exception
     */
    public static DistancematrixVo getDistancematrix(Double sLat, Double sLnt, Double eLat, Double eLnt) throws Exception{
    public static DistancematrixVo getDistancematrix(Double sLat, Double sLnt, Double eLat, Double eLnt, String tripId) throws Exception{
        GeoApiContext context = new GeoApiContext.Builder()
                .apiKey(key)
                .build();
@@ -205,6 +212,9 @@
        request.origins(new LatLng(sLat, sLnt));
        request.destinations(new LatLng(eLat, eLnt));
        request.mode(TravelMode.DRIVING);//出行方式(驾车)
        if(ToolUtil.isNotEmpty(tripId)){
            request.header("X-Goog-Maps-Experience-ID", tripId);//行程id
        }
        DistanceMatrix distanceMatrix = request.await();
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        System.out.println(gson.toJson(distanceMatrix));