您可以使用Point类开始了。
https://docs.oracle.com/javase/7/docs/api/java/awt/Point.html
int xE6 = x*1e6
int yE6 = y*1e6
new Point(xE6, yE6)
但由于这是AWT具体类的误用,你可能最终想要创建自己的。
public final class LatLon {
private double lat;
private double lon;
public LatLon(double lat, double lon) {
this.lat = lat;
this.lon = lon;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LatLon latLon = (LatLon) o;
if (Double.compare(latLon.lat, lat) != 0) return false;
return Double.compare(latLon.lon, lon) == 0;
}
@Override
public int hashCode() {
int result;
long temp;
temp = Double.doubleToLongBits(lat);
result = (int) (temp^(temp >>> 32));
temp = Double.doubleToLongBits(lon);
result = 31 * result + (int) (temp^(temp >>> 32));
return result;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}
(使用的IntelliJ自动生成的)
这可以像
public static void main(String[] args) {
HashMap<LatLon, Double> demo = new HashMap<LatLon, Double>();
demo.put(new LatLon(23.3445556,72.4535455), 0.23434);
demo.put(new LatLon(23.3645556,72.4235455), 0.53434);
demo.put(new LatLon(23.3245556,72.4635455), 0.21434);
demo.put(new LatLon(23.3645556,72.2535455), 0.25434);
System.out.println(demo.get(new LatLon(23.3645556,72.2535455))); //0.25434
}
使用的问题原样使用这个类,是它使用双打。你想要一些精确度,由小数点位置给出。
双打有奇怪的数学,并可以给你准确性的错误,所以我衷心推荐使用专为地理坐标设计的图书馆。
特别是考虑
如果(demo.latitude < 21.45454545 & & demo.longitude> 72.3455)
这类检查最好是通过某种特定目的建造收集用于处理服务如果你最终遇到了性能问题,则可以进行边界检查和协调。
把这个:*** 23.34444,72.23455 ***变成一个点类 –
听起来像你想要一个类代表经纬度值... –
看到https://stackoverflow.com/questions/30125954/storing-longitude-纬度值 – user7294900