io.hypertrack.utils.GeoJsonUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hypertrack-java Show documentation
Show all versions of hypertrack-java Show documentation
A Java wrapper for the HyperTrack API https://hypertrack.io
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