Reputation: 61
is it possible that I can get the coordinates of another phone when that phone has no WIFI on? I want to calculate the distance between two phones but none of the phones is connected on wifi. Is this possible?
Upvotes: 0
Views: 1481
Reputation: 4348
you can get distance between two latitude and Longitude So if you are able to get latitude and longitude between two device then you can get the distance using following code
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;
}
Upvotes: 2