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
The 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 string for request body.
*
* @param latLng List of latitude and longitude
* @return Serialized GeoJSON object
*/
public static String geoJsonFromLatLng(List latLng) {
Double longitude = latLng.get(1);
Double latitude = latLng.get(0);
String geoJson = "{\"coordinates\": [" + longitude.toString() + ", " + latitude.toString() + "], \"type\": \"Point\"}";
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