Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android find bearing on a fixed location

Tags:

android

I am very new to Android and learning through it. So i want to create a arrow like pointer to show where is the fixed location is fixed, as the users move their device, the arrow should automatically updated(like compass).

I have googled for resources but i couldn't manage to find it. Anyone here knows how to do it? any examples or tutorials would be much appreciated.

Example:

fixed location: 20 latitude, 50 longitude
my location: 5 latitude 25, longitude
So how do i find the arrow pointed to fixed location?
like image 428
cicakman Avatar asked Nov 20 '25 04:11

cicakman


1 Answers

If curLat and curLon are the current location's latitude and longitude and if refLat and refLon are the reference location latitude and longitude you may get the bearing from the current location to the reference location like this:

final float[] results= new float[3];
// The computed distance in meters is stored in results[0].
// If results has length 2 or greater, the initial bearing is stored in results[1].
// If results has length 3 or greater, the final bearing is stored in results[2].
Location.distanceBetween(curLat, curLon, refLat, refLong, results);
final float bearing = results[1];

If the distance grows result[2] differ more and more from results[1] unless the the course from the current location to the reference location follows a rhumb line (or loxodrome, see here: http://en.wikipedia.org/wiki/Rhumb_line).

like image 100
Stefan Avatar answered Nov 21 '25 18:11

Stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!