All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hypertrack.utils.GeoJsonUtils Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package io.hypertrack.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Utility class to work with GeoJson objects and POJOs.
 */
public class GeoJsonUtils {
    /**
     * Convert [latitude, longitude] to GeoJson object.
     *
     * @param   latLng      List of latitude and longitude
     * @return              GeoJson object as POJO
     */
    public static Map geoJsonFromLatLng(List latLng) {
        Map geoJson = new HashMap<>();
        geoJson.put("type", "Point");
        ArrayList lngLat = new ArrayList<>();
        lngLat.add(latLng.get(1));
        lngLat.add(latLng.get(0));
        geoJson.put("coordinates", lngLat);
        return geoJson;
    }

    /**
     * Convert GeoJson object to [latitude, longitude].
     *
     * @param   geoJson     GeoJson object as Map
     * @return              List of latitude and longitude
     */
    public static ArrayList latLngFromGeoJson(Map geoJson) {
        ArrayList lngLat = (ArrayList)geoJson.get("coordinates");
        ArrayList latLng = new ArrayList<>();
        latLng.add(lngLat.get(1));
        latLng.add(lngLat.get(0));
        return latLng;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy