使用 Google 地图 api 如何比较两个位置的 GPS 坐标(纬度、经度)
Using Google maps api how to cmpare GPS coordinates(latti , longi) of two locations
在一个 Android 应用程序中,我遇到了一个问题,有人知道地图上的 GPS 坐标信息,请帮忙。
问题是如果我有地图上两个不同点的坐标(纬度和经度)并且
我想检查这些点是否在地图上的同一位置
其次是根据任何标准这两个点彼此更近
例如 .. 如果该点位于另一个点的 100 米半径内,则它似乎更近。
可以用haversine公式计算两个点,
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);
}
你可以比较这个 distance.This 会做你的工作。
在一个 Android 应用程序中,我遇到了一个问题,有人知道地图上的 GPS 坐标信息,请帮忙。
问题是如果我有地图上两个不同点的坐标(纬度和经度)并且
我想检查这些点是否在地图上的同一位置 其次是根据任何标准这两个点彼此更近
例如 .. 如果该点位于另一个点的 100 米半径内,则它似乎更近。
可以用haversine公式计算两个点,
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);
}
你可以比较这个 distance.This 会做你的工作。