当手机没有WIFI时,我可以获得另一部手机的坐标吗?我想计算两部手机之间的距离,但没有一部手机在wifi上连接。这可能吗?
答案 0 :(得分:2)
public static float calculateDistance(float lat1, float lon1, float lat2, float lon2)
{
float dLat = (float) Math.toRadians(lat2 - lat1);
float dLon = (float) Math.toRadians(lon2 - lon1);
float a =
(float) (Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2));
float c = (float) (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
float d = earthRadius * c;
return d;
}