0

My code requires to find the distance between two Tablets and the direction of second Tablet with reference to the first one. Both the Tabs update their location every 10 seconds.

But the distance as well as the initial and final bearing values vary as the locations update.

Location.distanceBetween(destLatitude, destLongitude, sourceLatitude, sourceLongitude, result);
float calc_distance = result[0];
float InitBearing = result[1];
if(InitBearing<0) 
{
  InitBearing = 360-Math.abs(InitBearing);
}
float FinalBearing = result[2];
if(FinalBearing<0) 
{
FinalBearing = 360-Math.abs(FinalBearing);
}
pjakhar
  • 19
  • 3
  • Some idea of the scale of error you are seeing might help? If you are relying on GPS for these destination/source values, then these will probably vary a very small amount as you lose/pick up satellites. I think it's all to do with angles etc. – iaindownie Dec 28 '11 at 14:09
  • But the values of distance and direction vary in large magnitudes and in a non-linear fashion. For example, my two tablets are placed parallel top each other at an arms length, but distance value keeps on increasing at every one or two minute and after about 4-5 minutes, it comes back to its initial value and keeps on changing again. Same is the case with Bearing values, they give me the expected value for around 1 minute and after 4-5 minutes they will also vary by almost 90 degrees. Am I supposed to take something like Earth's magnetic field into consideration? Hope my question is not vague – pjakhar Dec 29 '11 at 05:10
  • When you say 'large magnitudes' can you be more specific? I don't know if I can help at all, but hope discussing it helps. I found this which might be relevant to your bearing issues [here](http://stackoverflow.com/questions/4819626/android-phone-orientation-overview-including-compass) – iaindownie Dec 29 '11 at 10:12
  • Ya sure. I am reading my distance values in metres. If initially it is 20 metres, after 4-5 minutes, it will become around 300 metres, even though both tablets are steady. After some more minutes, it's again 100 metres. – pjakhar Dec 29 '11 at 10:28
  • As an aside, I have seen that level of variation when using other GPS units out cycling. When a sat goes out of sight (so to speak) and another comes into play, I have seen my position jump wildly, and my altitude change too. What refresh rate are you using in updating? Is it essential to update so regularly for your app? – iaindownie Dec 29 '11 at 10:34
  • I went through the link given by you. It explains about issues related to Screen orientation. While testing I keep my both tablets steady on a single table. I don't move them at all. So, I must get some result which should not vary by large values irrelevantly. Is it the screen orientation issue related with my problem in some manner? – pjakhar Dec 29 '11 at 11:21
  • the locations of both Tabs are updated at every 10 seconds and I have kept the minimum distance 0 metres: locationManager.requestLocationUpdates(provider, 10000, 0, locationlistener); Also, Tablet1 receives location of Tablet2 every 10 seconds. SO there is continuous calculation of distance and bearing every 10 seconds. Had the variations been small, I would have accepted it but a 90 degree change in direction is something weird. – pjakhar Dec 29 '11 at 11:42
  • Sorry, I'm stumped. Last 'suggestion' - is your arithmetic OK? Looks fine to me, so this is just a thought - see [here](http://stackoverflow.com/questions/877524/calculating-coordinates-given-a-bearing-and-a-distance) for something I found in case your phantom movements are actually a magnitude effect. Good luck! – iaindownie Dec 29 '11 at 12:41

0 Answers0