Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在其他两个点之间找到地理点_Java_Android_Maps_Latitude Longitude - Fatal编程技术网

Java 如何在其他两个点之间找到地理点

Java 如何在其他两个点之间找到地理点,java,android,maps,latitude-longitude,Java,Android,Maps,Latitude Longitude,对于我的应用程序,我必须在谷歌地图上找到一个点的位置,只知道它位于其他两个点之间,以及坐标被捕获的时间(毫秒) 在我的代码中,假设A和B是给定的点,X是要查找的点,我: 计算A和B之间的距离 根据时间,我算出了从A到B的速度(微度/毫秒) 我找到了从A点到X点的距离(使用时间和速度) 使用类似三角形的规则,我从点A计算点X的纬度和经度 此工作流会在地图上显示错误,因此,X标记通常不在A和B标记之间的直线上 我怎样才能使它工作得更好?这是地球球形的问题吗 谢谢大家 代码如下: int ax

对于我的应用程序,我必须在谷歌地图上找到一个点的位置,只知道它位于其他两个点之间,以及坐标被捕获的时间(毫秒)

在我的代码中,假设A和B是给定的点,X是要查找的点,我:

  • 计算A和B之间的距离

  • 根据时间,我算出了从A到B的速度(微度/毫秒)

  • 我找到了从A点到X点的距离(使用时间和速度)

  • 使用类似三角形的规则,我从点A计算点X的纬度和经度

  • 此工作流会在地图上显示错误,因此,X标记通常不在A和B标记之间的直线上

    我怎样才能使它工作得更好?这是地球球形的问题吗

    谢谢大家

    代码如下:

        int ax = oldPoint.getLatitude();
        int ay = oldPoint.getLongitude();
    
        int bx = currentPoint.getLatitude();
        int by = currentPoint.getLongitude();
    
        long at = oldPoint.getDataRilevamento(); //get time first point
        long bt = currentPoint.getDataRilevamento(); // get time second point
        long xt = x.getDate(); // time of point to find
    
        int c1 = bx-ax;
        int c2 = by-ay;
        double hyp =  Math.sqrt(Math.pow(c1, 2) + Math.pow(c2, 2));
    
        double vel = hyp / (bt-at);
    
        double pos = vel*(xt - at);
    
        int posx = (int)((pos*c1)/hyp);
        int posy = (int)((pos*c2)/hyp);
    
        x.setLatitude(ax+posx); //set the latitude of X
        x.setLongitude(ay+posy); // set the longitude of X
    

    您的问题可以通过以下步骤解决

    • 计算点A和点B之间的距离。此计算称为解决“逆测地问题”,这在C.F.F.Karney的文章“2012”中进行了讨论。下面的代码使用的算法不如Karney文章中给出的算法精确。使用 公式正确,Android的微度,这是什么 和Get经度返回,必须转换为弧度, 使用如下公式:

        double radians = Math.toRadians((double)microdegrees/1000000);
      
    • 从A点和B点计算轴承(方向)(使用公式 这将不同于毕达哥拉斯公式,因为 地球是圆的,不是平的

    • 然后,您可以选择一个新的距离并计算给定的点X 点A和上一步中找到的方位角。这称为解决“直接测地问题”

    • 使用以下公式将生成点的弧度转换为微度:

        int microdegrees = (int)(Math.toDegrees(radians)*1000000);
      
    总而言之,我们有以下功能,我将其置于公共领域:

        public static int[] getIntermediatePoint(
            int startLatMicroDeg,
            int startLonMicroDeg,
            int endLatMicroDeg,
            int endLonMicroDeg,
            double t // How much of the distance to use, from 0 through 1
        ){
            // Convert microdegrees to radians
            double alatRad=Math.toRadians((double)startLatMicroDeg/1000000);
            double alonRad=Math.toRadians((double)startLonMicroDeg/1000000);
            double blatRad=Math.toRadians((double)endLatMicroDeg/1000000);
            double blonRad=Math.toRadians((double)endLonMicroDeg/1000000);
            // Calculate distance in longitude
            double dlon=blonRad-alonRad;
            // Calculate common variables
            double alatRadSin=Math.sin(alatRad);
            double blatRadSin=Math.sin(blatRad);
            double alatRadCos=Math.cos(alatRad);
            double blatRadCos=Math.cos(blatRad);
            double dlonCos=Math.cos(dlon);
            // Find distance from A to B
            double distance=Math.acos(alatRadSin*blatRadSin +
                                      alatRadCos*blatRadCos *
                                      dlonCos);
            // Find bearing from A to B
            double bearing=Math.atan2(
                Math.sin(dlon) * blatRadCos,
                alatRadCos*blatRadSin -
                alatRadSin*blatRadCos*dlonCos);
            // Find new point
            double angularDistance=distance*t;
            double angDistSin=Math.sin(angularDistance);
            double angDistCos=Math.cos(angularDistance);
            double xlatRad = Math.asin( alatRadSin*angDistCos +
                                       alatRadCos*angDistSin*Math.cos(bearing) );
            double xlonRad = alonRad + Math.atan2(
                Math.sin(bearing)*angDistSin*alatRadCos,
                angDistCos-alatRadSin*Math.sin(xlatRad));
            // Convert radians to microdegrees
            int xlat=(int)Math.round(Math.toDegrees(xlatRad)*1000000);
            int xlon=(int)Math.round(Math.toDegrees(xlonRad)*1000000);
            if(xlat>90000000)xlat=90000000;
            if(xlat<-90000000)xlat=-90000000;
            while(xlon>180000000)xlon-=360000000;
            while(xlon<=-180000000)xlon+=360000000;
            return new int[]{xlat,xlon};
        }
    

    谢谢你发布这个算法。我需要为我的项目做一些类似的事情,我相信这样做就可以了!你介意我把它打包并作为npm模块发布吗?即使三年多之后:起首部分!谢谢你!我将它重写为PL/SQL作为服务器端函数,它完成了我想要的功能。
    int ax = oldPoint.getLatitude();
    int ay = oldPoint.getLongitude();
    
    int bx = currentPoint.getLatitude();
    int by = currentPoint.getLongitude();
    
    long at = oldPoint.getDataRilevamento(); //get time first point
    long bt = currentPoint.getDataRilevamento(); // get time second point
    long xt = x.getDate(); // time of point to find
    
    // Find relative time from point A to point B
    double t=(bt==at) ? 0 : ((double)(xt-at))/((double)(bt-at));
    // Find new point given the start and end points and the relative time
    int[] xpos=getIntermediatePoint(ax,ay,bx,by,t);
    x.setLatitude(xpos[0]); //set the latitude of X
    x.setLongitude(xpos[1]); // set the longitude of X