有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    试试这个,你会走得更远

     private String distance(double lati, double longi, double curlati1,
            double curlongi1) {
    
        double theta = longi - curlongi1;
        double dist = Math.sin(deg2rad(lati)) * Math.sin(deg2rad(curlati1))
                + Math.cos(deg2rad(lati)) * Math.cos(deg2rad(curlati1))
                * Math.cos(deg2rad(theta));
        dist = Math.acos(dist);
        dist = rad2deg(dist);
        dist = dist * 60 * 1.1515;
    
        dist = dist * 1.609344;
    
        result = Double.toString(dist);
        System.out.println("dist_result :" + result);
        return (result);
    }
    
    /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
    /* :: This function converts decimal degrees to radians : */
    /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
    private double deg2rad(double deg) {
        return (deg * Math.PI / 180.0);
    }
    
    /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
    /* :: This function converts radians to decimal degrees : */
    /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
    private double rad2deg(double rad) {
        return (rad * 180.0 / Math.PI);
    }
    
  2. # 2 楼答案

    您可以使用Android SDK函数distanceBetween

    Computes the approximate distance in meters between two locations, and optionally the initial and final bearings of the shortest path between them. Distance and bearing are defined using the WGS84 ellipsoid.