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


Maybe the hashmap is not sobad afterall. Consider this?



static class Coords {
 ...
}

Map<Coords, String> map = new HashMap<Coords, String>();
map.put(new Coords(1700, 1272), "Some_ship");

      

+1


source


class Ship {
    ArrayList<Coordinate> coordinates;
}

ArrayList<Ship> ships;

      

0


source


Without a chunk of data file to view, it is difficult to answer this question. The ArrayList will appear perfect and create ship objects with their coordinates.

If you want to do a hashmap, I guess the ship would be the best key.

0


source







All Articles