本文介绍了存储经度和纬度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有5000多个船舶坐标,它们是经度&纬度坐标。我想知道每艘船存放这些的最佳方法是什么。每艘船的坐标数量都是未知的。

最初我还在想一个类似的双2D数组:

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[][];

但我不知道我需要的尺寸。

我不知道 Hashmap 是否可以工作,因为没有真正的密钥,我在想一个 ArrayList 列表,但我不确定实施情况以及它是否是最可行的选择。

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.

推荐答案

制作 ShipCoordinates

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));

这篇关于存储经度和纬度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 22:18