Java 谷歌地图中从一点到另一点的线条移动

Java 谷歌地图中从一点到另一点的线条移动,java,google-maps,google-maps-api-2,Java,Google Maps,Google Maps Api 2,我需要在谷歌地图应用程序中将一个标记从一个点移动到另一个点。但是,我在使用LatLng坐标时遇到了问题,特别是因为精度误差 我尝试了2d运动的基本方法,但它似乎不是地球坐标的正确方法 double dx = target.longitude - position.longitude; double dy = target.latitude - position.latitude; //Auxiliar.distance returns the d

我需要在谷歌地图应用程序中将一个标记从一个点移动到另一个点。但是,我在使用LatLng坐标时遇到了问题,特别是因为精度误差

我尝试了2d运动的基本方法,但它似乎不是地球坐标的正确方法

        double dx = target.longitude - position.longitude;
        double dy = target.latitude - position.latitude;

        //Auxiliar.distance returns the distance in meters between two coordinates
        double lenght = Auxiliar.distance(target, position);

        dx *= SPEED/lenght;
        dy *= SPEED/lenght;

        position = new LatLng(position.latitude + dy, 
                                position.longitude + dx);
我在尝试减去坐标时也会出现精度错误,因为它们是双倍的,所以我尝试使用BigDecimal,但仍然没有成功

在地球坐标系中有一个直线运动的算法吗


这是我的距离函数的代码

public static double distance(LatLng point1, LatLng point2)
{
    double earthRadius = 6371 ;
    double dLat = Math.toRadians(point2.latitude-point1.latitude);
    double dLng = Math.toRadians(point2.longitude-point1.longitude);
    double sindLat = Math.sin(dLat / 2);
    double sindLng = Math.sin(dLng / 2);
    double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)
            * Math.cos(Math.toRadians(point1.latitude)) * Math.cos(Math.toRadians(point2.latitude));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    double dist = earthRadius * c;

    return dist*1000;
}

你能提供一个到文件的链接吗?请记住,纬度和经度是Angel。我使用哈弗森公式计算距离,正如这里所回答的,我将用代码编辑我的问题