Comments and 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 comments and answers for the question "GPS 2D compass to point to Longitude and Latitude"Comment by ibrahim2unityfocus on ibrahim2unityfocus's comment
http://answers.unity.com/comments/1562281/view.html
Hello,
Well, as you see in the answer all you need is to create the method angleFromCoordinate and use the other code snippet in the update method. You will need to enable the GPS. After that, just drag and drop the script on the object and it should work.Sat, 13 Oct 2018 11:59:12 GMTibrahim2unityfocusComment by Eeyung on Eeyung's answer
http://answers.unity.com/comments/1561921/view.html
Hi, may i know how to apply it to a gameobject? let's say i want an arrow(game object) always point to the destination coordinate during runtime, it is allow to apply it to a game object?Fri, 12 Oct 2018 04:40:15 GMTEeyungComment by ibrahimAlfors on ibrahimAlfors's answer
http://answers.unity.com/comments/1501375/view.html
One strange thing thou, if you flip your phone on its screen, it also flips the compass and makes the bearing inverted. Not sure how to fix that thou.Wed, 02 May 2018 22:30:53 GMTibrahimAlforsAnswer 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 GMTibrahimAlforsComment by TanselAltinel
http://answers.unity.com/comments/1501342/view.html
Do you need to understand the calculation? Because I've worked with GIS systems for so long and all calculations are used as they are, just usually translated into programming language that is being used at the specific project.
Did you try the calculation in the link you provided? Did you take the answer into consideration?Wed, 02 May 2018 20:12:13 GMTTanselAltinel