Get direction (compass) with two longitude/latitude points

O forgot to say I found the answer eventually. The application is to determine compass direction of a transit vehicle and its destination. Essentially, fancy math for acquiring curvature of Earth, finding an angle/compass reading, and then matching that angle with a generic compass value. You could of course just keep the compassReading and apply … Read more

iPhone Compass GPS Direction

There is a standard “heading” or “bearing” equation that you can use – if you are at lat1,lon1, and the point you are interested in is at lat2,lon2, then the equation is: heading = atan2( sin(lon2-lon1)*cos(lat2), cos(lat1)*sin(lat2) – sin(lat1)*cos(lat2)*cos(lon2-lon1)) This gives you a bearing in radians, which you can convert to degrees by multiplying by … Read more

How to rotate a Direction Arrow to particular location

This works for me: to rotate a Direction Arrow to particular location -(void)viewDidLoad { [super viewDidLoad]; locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = kCLDistanceFilterNone; } -(void) calculateUserAngle:(CLLocationCoordinate2D)current { double x = 0, y = 0 , deg = 0,delLon = 0; delLon = fixLon – current.longitude; y = sin(delLon) … Read more

Android phone orientation overview including compass

You might want to check out the One Screen Turn Deserves Another article. It explains why you need the rotation matrix. In a nutshell, the phone’s sensors always use the same coordinate system, even when the device is rotated. In applications that are not locked to a single orientation, the screen coordinate system changes when … Read more

how to calculate phone’s movement in the vertical direction from rest?

If you integrate the acceleration twice you get position but the error is horrible. It is useless in practice. Here is an explanation why (Google Tech Talk) at 23:20. I highly recommend this video. Now, you do not need anything accurate and that is a different story. The linear acceleration is available after sensor fusion, … Read more

Android getOrientation Azimuth gets polluted when phone is tilted

For complete code see https://github.com/hoananguyen/dsensor Keep a history and average out, I do not know the correct interpretation of pitch and roll so the following code is for azimuth only. Class members private List<float[]> mRotHist = new ArrayList<float[]>(); private int mRotHistIndex; // Change the value so that the azimuth is stable and fit your requirement … Read more

Calculate compass bearing / heading to location in Android

Ok I figured this out. For anyone else trying to do this you need: a) heading: your heading from the hardware compass. This is in degrees east of magnetic north b) bearing: the bearing from your location to the destination location. This is in degrees east of true north. myLocation.bearingTo(destLocation); c) declination: the difference between … Read more