使用谷歌地图api如何cmpare两个位置的GPS坐标(latti,longi)

时间:2015-10-17 09:50:10

标签: android google-maps google-maps-api-3 gps

在一个Android应用程序中,我遇到了一个问题,任何人都有来自地图的GPS坐标信息,请帮忙。

问题是如果我在地图和

上有两个不同点的坐标(纬度和经度)

我想检查这些点是否在地图上的相同位置 其次,根据任何标准,两点相互靠近

例如..如果该点位于另一点的100米半径内,则它似乎更接近。

1 个答案:

答案 0 :(得分:0)

您可以使用hasrsine公式计算两个点,

 public static void main(String[] args) {
    // TODO Auto-generated method stub
    final int R = 6371; // Radious of the earth
    Double lat1 = Double.parseDouble(args[0]);
    Double lon1 = Double.parseDouble(args[1]);
    Double lat2 = Double.parseDouble(args[2]);
    Double lon2 = Double.parseDouble(args[3]);
    Double latDistance = toRad(lat2-lat1);
    Double lonDistance = toRad(lon2-lon1);
    Double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + 
               Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * 
               Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
    Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    Double distance = R * c;

    System.out.println("The distance between two lat and long is::" + distance);

}

你可以比较这个距离。这将完成你的工作。