0

I am an IOS beginner. I need to calculate distance between bluetooth devices. When I google it I couldn't find the formula to measure the distance between devices, everything is in theory which I couldn't able to understand.So if there is any direct formula to measure the distance using the signal strength it will be cool. Any help is appreciated.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Gopinath Shiva
  • 3,822
  • 5
  • 25
  • 48
  • 2
    My first thought would be, that this is not possible. There are to many unknown factors to make this translation. Interference or antenna strength for example. I've seen different signal strengths for equal distances, on different devices. Unreliable for distance-measuring, probably – fguchelaar Dec 06 '13 at 14:56
  • is there anyway to measure the correct distance between the devices using any method? – Gopinath Shiva Dec 06 '13 at 14:58

1 Answers1

1

If there is a server side involved in your app, you can get the coordinates of both the devices using CLLocationManager Class and then calculates the distance using following function.

#define d2r (M_PI / 180.0)

+(float) haversine_km:(float)lat1: (float)long1: (float)lat2: (float)long2
{
float dlong = (long2 - long1) * d2r;
float dlat = (lat2 - lat1) * d2r;
float a = pow(sin(dlat/2.0), 2) + cos(lat1*d2r) * cos(lat2*d2r) * pow(sin(dlong/2.0), 2); 
float c = 2 * atan2(sqrt(a), sqrt(1-a));
float d = 6367 * c;

return d;
}


Where lat1, long1 are the coordinates of first device and lat2, long2 are the coordinates of second device. The result will be in Kilometers and off course you can convert it to your desired unit.

Shahid Iqbal
  • 2,059
  • 2
  • 21
  • 29