从两个坐标计算中点 [英] Calculating midpoint from two coordinates

查看:121
本文介绍了从两个坐标计算中点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到两个点之间的中点时有一些问题。这里就是我得到两个点之间的最短距离的一部分:

 双距离= 0;
                    双minDistance依旧= Double.MAX_VALUE;

                    convertedHotSpotGeomList = RetrieveHotSpotAsyncTask.convertedHotSpotGeom;
                    经纬度[] minPoints =新的经纬度[2];

                    的for(int i = 0; I< convertedHotSpotGeomList.size();我++){
                        经纬度点1 =新经纬度(convertedHotSpotGeomList.get(ⅰ).getY(),convertedHotSpotGeomList.get(ⅰ).getX());
                        经纬度点2 =新的经纬度(convertedHotSpotGeomList.get(+ I).getY(),convertedHotSpotGeomList.get(++ I).getX());

                        距离= calculateDistance(点1,点2);
                        如果(距离< minDistance依旧){
                            minDistance依旧=距离;
                            minPoints [0] =点1;
                            minPoints [1] =点2;
                        }
                    }

                    //完成所有的比较,得出的圈子
                    如果(minPoints [0] =空&安培;!&安培;!minPoints [1] =空){
                        CircleOptions circleOptions =新CircleOptions()
                            .center(minPoints [0])
                            .radius(1000)
                            .fillColor(Color.argb(95,178,30,37))
                            .strokeColor(Color.TRANSPARENT);
                        CircleOptions circleOptions1 =新CircleOptions()
                            .center(minPoints [1])
                            .radius(1000)
                            .fillColor(Color.argb(95,88,130,37))
                            .strokeColor(Color.TRANSPARENT);

                        googleBasemap.addCircle(circleOptions);
                        googleBasemap.addCircle(circleOptions1);

                        中点(minPoints [0] .latitude,minPoints [0] .longitude,minPoints [1] .latitude,minPoints [1] .longitude);
                    }
                }
 

再从两个圆我画的中心点,我调用此方法来获取中间点:

 私人无效中点(双LAT1,双lon1,双LAT2,双lon2){
    双dLon = Math.toRadians(lon2  -  lon1);

    LAT1 = Math.toRadians(LAT1);
    LAT2 = Math.toRadians(LAT2);
    lon1 = Math.toRadians(lon1);

    双的Bx = Math.cos(LAT2)* Math.cos(dLon);
    双增= Math.cos(LAT2)* Math.sin(dLon);
    双lat3 = Math.atan2(Math.sin(LAT1)+ Math.sin(LAT2)的Math.sqrt((Math.cos(LAT1)+ Bx的)*(Math.cos(LAT1)+ Bx的)+按*通过));
    双lon3 = lon1 + Math.atan2(通过,Math.cos(LAT1)+ Bx的);

    Log.i(LAT,将String.valueOf(lat3));
    Log.i(LON,将String.valueOf(lon3));
    CircleOptions circleOptions =新CircleOptions()
    .center(新经纬度(lon3,lat3))
    .radius(1000)
    .fillColor(Color.argb(95,178,30,137))
    .strokeColor(Color.TRANSPARENT);

    googleBasemap.addCircle(circleOptions);
}
 

目前的中点,我想画另一个圈子到谷歌地图。然而,当我打印出来的纬度和经度为中点,我得到这样的:

  LAT 0.02512664 LON 1.811859
 

对谷歌地图

据我所知道,坐标应该是103,1。我想这是因为该格式是不同的,这就是为什么第三个圆不出来。任何想法?

在此先感谢。

解决方案

 双lat3 = Math.atan2(Math.sin(LAT1)+ ...
 双lon3 = lon1 + Math.atan2(通过,Math.cos(LAT1)+ Bx的);
 

这将返回弧度。去度:

 双latdeg = Math.toDegrees(lat3);
双londeg = Math.toDegrees(lon3);


103.81187377279383
1.4396504253445948
 

I was having some problem when trying to find the mid point between two point. Here is the part where I get the shortest distance between two point:

                    double distance = 0;
                    double minDistance = Double.MAX_VALUE;

                    convertedHotSpotGeomList = RetrieveHotSpotAsyncTask.convertedHotSpotGeom;
                    LatLng[] minPoints = new LatLng[2]; 

                    for(int i = 0; i < convertedHotSpotGeomList.size(); i++){
                        LatLng point1 = new LatLng(convertedHotSpotGeomList.get(i).getY(),   convertedHotSpotGeomList.get(i).getX());                                 
                        LatLng point2 = new LatLng(convertedHotSpotGeomList.get(++i).getY(), convertedHotSpotGeomList.get(++i).getX());

                        distance = calculateDistance(point1, point2);
                        if(distance < minDistance){
                            minDistance = distance;
                            minPoints[0] = point1;
                            minPoints[1] = point2;
                        }
                    }

                    // Finish all the comparison and draw the circles
                    if(minPoints[0]!=null && minPoints[1] !=null){
                        CircleOptions circleOptions = new CircleOptions()
                            .center(minPoints[0])
                            .radius(1000)
                            .fillColor(Color.argb(95, 178, 30, 37))
                            .strokeColor(Color.TRANSPARENT);
                        CircleOptions circleOptions1= new CircleOptions()
                            .center(minPoints[1])
                            .radius(1000)
                            .fillColor(Color.argb(95, 88, 130, 37))
                            .strokeColor(Color.TRANSPARENT);

                        googleBasemap.addCircle(circleOptions);
                        googleBasemap.addCircle(circleOptions1);

                        midPoint(minPoints[0].latitude,minPoints[0].longitude,minPoints[1].latitude,minPoints[1].longitude);
                    }
                }

And then from the center point of the two circles I drawn, I am calling this method to get the midpoint:

private void midPoint(double lat1,double lon1,double lat2,double lon2){
    double dLon = Math.toRadians(lon2 - lon1);

    lat1 = Math.toRadians(lat1);
    lat2 = Math.toRadians(lat2);
    lon1 = Math.toRadians(lon1);

    double Bx = Math.cos(lat2) * Math.cos(dLon);
    double By = Math.cos(lat2) * Math.sin(dLon);
    double lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
    double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);

    Log.i("LAT", String.valueOf(lat3));
    Log.i("LON", String.valueOf(lon3));
    CircleOptions circleOptions = new CircleOptions()
    .center(new LatLng(lon3, lat3))
    .radius(1000)
    .fillColor(Color.argb(95, 178, 30, 137))
    .strokeColor(Color.TRANSPARENT);

    googleBasemap.addCircle(circleOptions);
}

At the midpoint, I wanted to draw another circle onto the google map. However, when I print out the lat and lng for the mid point, I am getting this:

LAT 0.02512664 LON 1.811859

From what I've known, the coordinate of google map should be in 103. , 1. . I guess it's because the format is different and that's why the third circle is not coming out. Any ideas?

Thanks in advance.

解决方案

 double lat3 = Math.atan2(Math.sin(lat1) +...
 double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);

This returns radians. Go to degrees:

double latdeg = Math.toDegrees(lat3);
double londeg = Math.toDegrees(lon3);


103.81187377279383
1.4396504253445948

这篇关于从两个坐标计算中点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆