我正在使用开放的街道地图。现在我可以获取地图中的所有交点,并可以获取它们的经度和纬度。我的应用程序中有 GPS 我想做的是找到离我的 GPS 坐标最近的交点 这是我的方法,但不是非常精准 。我只需要帮助知道为什么!谢谢..
public Nodee nearestPoint(double longitude, double latitude) throws Exception {
    inters = new ArrayList<Nodee>();
    inters = getIntersections();
    double minLong = Math.abs(longitude - (inters.get(0).lon));
    double minLat = Math.abs(latitude - (inters.get(0).lat));
    Nodee NearestNodeLong = null;
    Nodee NearestNodeLat = null;
    for (int i = 0; i < inters.size(); i++) {
        if (Math.abs((inters.get(i).lon) - longitude) < minLong) {
            minLong = (Math.abs((inters.get(i).lon) - longitude));
            NearestNodeLong = inters.get(i);
    } 
        if (Math.abs((inters.get(i).lat) - latitude) < minLat) {
            minLat = Math.abs((inters.get(i).lat) - latitude);
            NearestNodeLat = inters.get(i);
        } 
    }
    if (NearestNodeLong.equals(NearestNodeLat)) {
        return NearestNodeLong;
    } else if (!NearestNodeLong.equals(NearestNodeLat)) {
        Double d1 = (double) distFrom(latitude, longitude, (NearestNodeLat.lat),
                (NearestNodeLat.lon));
        Double d2 = (double) distFrom(latitude, longitude, (NearestNodeLong.lat),
                (NearestNodeLong.lon));
        if (d1 < d2)
            return NearestNodeLat;
        else if (d2 < d1)
            return NearestNodeLong;
    }
    return null;
}