Adding distance to a GPS coordinate

后端 未结 5 1106
南旧
南旧 2020-11-28 05:32

I\'m trying to generate some points at random distances away from a fixed point using GPS.

How can I add distance in meters to a GPS coordinate? I\'ve looked at UTM

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 05:38

    This code splits the line between two coordinates in n segments. Replace the delta calculation by your fixed distance

     @Override
    public void split(Coordinates p1, Coordinates p2, int segments) {
        double φ1 = Math.toRadians(p1.getLat());
        double λ1 = Math.toRadians(p1.getLon());
        double φ2 = Math.toRadians(p2.getLat());
        double λ2 = Math.toRadians(p2.getLon());
    
    
        double xDelta = (φ2 - φ1) / segments;
        double yDelta = (λ2 - λ1) / segments;
        for (int i = 0; i < segments; i++){
            double x = φ1 + i * xDelta;
            double y = λ1 + i * yDelta;
            double xc = Math.toDegrees(x);
            double yc = Math.toDegrees(y);
            System.out.println(xc+","+yc);
        }
    }
    

提交回复
热议问题