Saving Longitude and Latitude Values
So I have 5000+ ship coordinates, they are longitude and latitude coordinates. I'm wondering what would be the best way to save them for each ship. Each ship will have an unknown number of coordinates.
I originally thought about double 2D array too:
double [][] array = new double[][];
But I have no idea what size I need.
I don't know if this will work Hashmap
as there is no real "key" I was thinking of ArrayList
from List
, but I was not sure about the implementation and if this is the most viable option.
0
source to share
4 answers
Make a class ShipCoordinates
public class ShipCoordinates {
public final double latitude;
public final double longitude;
public ShipCoordinates(double lat, double lon) {
latitude = lat;
longitude = lon;
}
}
And keep these objects in a list
List<ShipCoordinates> shipCoordinates = new ArrayList<>();
// Example of valid ship coordinates off the coast of California :-)
shipCoordinates.add(new ShipCoordinates(36.385913, -127.441406));
+3
source to share