Script to rotate to GPS coords for missile launcher?

Code taken from here: http://forum.keenswh.com/threads/getdirectionto-function.7242345/

Given the target coordinates (target vector), and three blocks (two placed horizontally and the third placed vertically), this code measures the distance between the blocks and the targets and adjusts pitch and yaw until each pair of blocks is perpendicular to the target.

/*
VRageMath.Vector3D TV         This is the target vector.
IMyTerminalBlock Origin       Origin block.
IMyTerminalBlock Forward      Block directly in front of the origin.
IMyTerminalBlock Up           Block directly above the origin.
IMyTerminalBlock Right        Block directly to the right of the origin.
ref double Pitch              Reference to Pitch.
ref double Yaw                Reference to Yaw.
*/
void GetDirectionTo(VRageMath.Vector3D TV, IMyTerminalBlock Origin, IMyTerminalBlock Forward, IMyTerminalBlock Up, IMyTerminalBlock Right, ref double Pitch, ref double Yaw)
{
  VRageMath.Vector3D OV = Origin.GetPosition();     //Get positions of reference blocks.
  VRageMath.Vector3D FV = Forward.GetPosition();
  VRageMath.Vector3D UV = Up.GetPosition();
  VRageMath.Vector3D RV = Right.GetPosition();

  double TVOV = (OV - TV).Length();     //Get magnitudes of vectors.

  double TVFV = (FV - TV).Length();
  double TVUV = (UV - TV).Length();
  double TVRV = (RV - TV).Length();

  double OVFV = (FV - OV).Length();
  double OVUV = (UV - OV).Length();
  double OVRV = (RV - OV).Length();

  double ThetaP = Math.Acos((TVUV * TVUV - OVUV * OVUV - TVOV * TVOV) / (-2 * OVUV * TVOV));     //Use law of cosines to determine angles.
  double ThetaY = Math.Acos((TVRV * TVRV - OVRV * OVRV - TVOV * TVOV) / (-2 * OVRV * TVOV));

  double RPitch = 90 - (ThetaP * 180 / Math.PI);     //Convert from radians to degrees.
  double RYaw = 90 - (ThetaY * 180 / Math.PI);

  if (TVOV < TVFV) RPitch = 180 - RPitch;     //Normalize angles to -180 to 180 degrees.
  if (RPitch > 180) RPitch = -1 * (360 - RPitch);

  if (TVOV < TVFV) RYaw = 180 - RYaw;
  if (RYaw > 180) RYaw = -1 * (360 - RYaw);

  Pitch = RPitch;     //Set Pitch and Yaw outputs.
  Yaw = RYaw;
}

Here's an implementation of this code. It's from this thread, but the URL doesn't work anymore. You would have to change the part where it takes the coordinates from the sensor (line 48) and instead input the GPS coordinates yourself directly in the code or as a block name.

/r/spaceengineers Thread