7 Replies Latest reply on Nov 7, 2012 1:57 PM by comment

# Calculate LAT/LON Bearing

How do you calculate a bearing from one LAT-LON to another LAT-LON

Distance is OK, but every formula I tried for bearing reports too many parameters, etc.

Does any one have a working calculation?

Distance is:

TIA

Guy

• ###### 2. Re: Calculate LAT/LON Bearing

Been there, but none work in FM...I'm not trig whiz, just want a copy-paste solution.

• ###### 4. Re: Calculate LAT/LON Bearing

I thought this was the developer forum.

• ###### 5. Re: Calculate LAT/LON Bearing

Meaning?

Developers help developers... we all can't know everything about everything.

I've deployed many FM solutions and having fun with FM GO.  I'm not a math whiz, so unless you can offer some helpful posts...

• ###### 6. Re: Calculate LAT/LON Bearing

To translate the math (and non-FileMaker code) into a calculation that will work in FileMaker, try this:

// BearingFinal ( latitude1 ; longitude1 ; latitude2 ; longitude2 )

Let ( [

// reverse order of inputs to get final bearing rather than initial bearing

~latitude1 = Radians ( latitude2 );

~latitude2 = Radians ( latitude1 );

~longitudeDifference = Radians ( longitude1 - longitude2 );

~y = Sin ( ~longitudeDifference ) * Cos ( ~latitude2 );

~x =

Cos ( ~latitude1 ) * Sin ( ~latitude2 )

- Sin ( ~latitude1 ) * Cos ( ~latitude2 ) * Cos ( ~longitudeDifference );

~bearing =

Case (

~x = 0 and ~y ≥ 0 ; 90;          // degrees

~x = 0          /* and ~y < 0 */ ; 270;

/* Else */ Degrees ( Atan ( ~y / ~x ) )

);

~bearing = // correct ~bearing for quadrant

Case (

/* quadrants 2 & 3 */ ~x < 0;

180 + ~bearing;

/* quadrant 4 */ ~y < 0;          // and ~x ≥ 0

Mod ( 360 + ~bearing ; 360 );

~bearing

)

];

// reverse input, since we're looking for final bearing rather than initial bearing

Mod ( 180 + ~bearing ; 360 )

)

• ###### 7. Re: Calculate LAT/LON Bearing

You are most welcome.