converting negative heading

440 views
Skip to first unread message

HansW

unread,
Jan 8, 2012, 10:14:51 AM1/8/12
to Google Maps JavaScript API v3
Hi,

I am trying to make a if then for a google map heading to return 0 to
360 degrees, I am reading my first book on this subject and am not
proficient yet.

Something goes wrong obviously, however I do not understand why:

var heading = google.maps.geometry.spherical.computeHeading(path[0],
path[1]); if (heading>0) return Math.round(heading);
else if (heading<=0) return Math.round(360-heading);
return heading;

Thanks for any replies.

davie

unread,
Jan 8, 2012, 4:50:38 PM1/8/12
to Google Maps JavaScript API v3
Hi

Return is used in javascript for two reasons.
You want the script to stop executing if something happens.
You want the function to return a value to the calling function.
Try
var newVar;
var heading =
google.maps.geometry.spherical.computeHeading(path[0],path[1]);
if (heading>0)
newVar = Math.round(heading);
else
newVar = Math.round(360-heading);

Or just use heading instead of newVar if appropriate
ie
var heading =
google.maps.geometry.spherical.computeHeading(path[0],path[1]);
if (heading>0)
heading = Math.round(heading);
else
heading = Math.round(360-heading);
Regards Davie
Reply all
Reply to author
Forward
0 new messages