Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Longitude and Latitude values

Tags:

java

So I have 5000+ ship coordinates, They're Longitude & Latitude coordinates. I'm wondering what would be the best way to store these for each ship. Each ship will have an unknown amount of coordinates.
Initially I was thinking a double 2D array similar too:

double [][] array = new double[][]; 

But I have no idea of the size I will need.
I don't know if a Hashmap will work since there's no real "key", I was thinking an ArrayList of List's, but I was not sure on the implementation and if it's the most viable option.

like image 427
guy_sensei Avatar asked Oct 16 '25 08:10

guy_sensei


2 Answers

Make a ShipCoordinatesclass

public class ShipCoordinates {
    public final double latitude;
    public final double longitude;

    public ShipCoordinates(double lat, double lon) {
        latitude = lat;
        longitude = lon;
    }
}

And store these objects into 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));
like image 118
Shar1er80 Avatar answered Oct 18 '25 22:10

Shar1er80


Maybe 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");
like image 42
Vollmilchbb Avatar answered Oct 18 '25 21:10

Vollmilchbb