Answers for "GPS 2D compass to point to Longitude and Latitude"
http://answers.unity.com/questions/1500577/gps-2d-compass-to-point-to-longitude-and-latitude.html
The latest answers for the question "GPS 2D compass to point to Longitude and Latitude"Answer by ibrahimAlfors
http://answers.unity.com/answers/1501373/view.html
I was able to find a solution for those who want to use it, I used this link
https://stackoverflow.com/questions/3932502/calculate-angle-between-two-latitude-longitude-points
here is my code
private float angleFromCoordinate(float lat1, float long1, float lat2, float long2) {
lat1 *= Mathf.Deg2Rad;
lat2 *= Mathf.Deg2Rad;
long1 *= Mathf.Deg2Rad;
long2 *= Mathf.Deg2Rad;
float dLon = (long2 - long1);
float y = Mathf.Sin(dLon) * Mathf.Cos(lat2);
float x = (Mathf.Cos(lat1) * Mathf.Sin(lat2)) - (Mathf.Sin(lat1) * Mathf.Cos(lat2) * Mathf.Cos(dLon));
float brng = Mathf.Atan2(y, x);
brng = Mathf.Rad2Deg* brng;
brng = (brng + 360) % 360;
brng = 360 - brng;
return brng;
}
and to use it, in the Update Method:
float bearing = angleFromCoordinate(current.latitude,current.longitude,
destination.latitude,destination.longitude);
compass.rotation = Quaternion.Slerp(compass.rotation, Quaternion.Euler(0, 0, Input.compass.magneticHeading + bearing), 100f);
I hope this help you guys.
Thanks.Wed, 02 May 2018 22:29:13 GMTibrahimAlfors