Android 使用Google maps api如何比较两个位置的GPS坐标(latti、longi)
在一个Android应用程序中,我遇到了一个问题,任何人都可以从地图上获得有关GPS坐标的信息,请帮助 问题是如果我有地图上两个不同点的坐标(纬度和经度)和 我想检查这些点是否在地图上的同一位置 其次,根据任何标准,这两点都更接近Android 使用Google maps api如何比较两个位置的GPS坐标(latti、longi),android,google-maps,google-maps-api-3,gps,Android,Google Maps,Google Maps Api 3,Gps,在一个Android应用程序中,我遇到了一个问题,任何人都可以从地图上获得有关GPS坐标的信息,请帮助 问题是如果我有地图上两个不同点的坐标(纬度和经度)和 我想检查这些点是否在地图上的同一位置 其次,根据任何标准,这两点都更接近 例如。。如果该点位于另一点的100m半径内,则该点似乎更近 您可以使用哈弗森公式计算两点 public static void main(String[] args) { // TODO Auto-generated method stub fina
例如。。如果该点位于另一点的100m半径内,则该点似乎更近 您可以使用哈弗森公式计算两点
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);
}
你可以比较一下这段距离,这样就可以了 您可以使用哈弗森公式计算两点
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);
}
你可以比较一下这段距离,这样就可以了 地点1.地点2.地点1.地点2.地点2.地点1.地点2.地点2.地点2.地点2.地点2.地点1.地点1.地点2。。。但是我对这个公式有点困惑。。。你能告诉我关于哈弗森的药方吗。实际上,代码本身解释了这一切。不管怎样,关于这个公式你还想知道什么?谢谢你的回答…我得到了你的建议…这似乎是一个解决方案。。。但是我对这个公式有点困惑。。。你能告诉我关于哈弗森的药方吗。实际上,代码本身解释了这一切。不管怎样,关于这个公式你还想知道什么?