function computeOffsetOrigin(to, distance, heading) {
  heading = toRadians(heading);
  distance /= EARTH_RADIUS;
  // http://lists.maptools.org/pipermail/proj/2008-October/003939.html
  var n1 = Math.cos(distance);
  var n2 = Math.sin(distance) * Math.cos(heading);
  var n3 = Math.sin(distance) * Math.sin(heading);
  var n4 = Math.sin(toRadians(to.lat));
  // There are two solutions for b. b = n2 * n4 +/- sqrt(), one solution results
  // in the latitude outside the [-90, 90] range. We first try one solution and
  // back off to the other if we are outside that range.
  var n12 = n1 * n1;
  var discriminant = n2 * n2 * n12 + n12 * n12 - n12 * n4 * n4;
  if (discriminant < 0) {
    // No real solution which would make sense in LatLng-space.
    return null;
  }
  var b = n2 * n4 + Math.sqrt(discriminant);
  b /= n1 * n1 + n2 * n2;
  var a = (n4 - n2 * b) / n1;
  var fromLatRadians = Math.atan2(a, b);
  if (fromLatRadians < -Math.PI / 2 || fromLatRadians > Math.PI / 2) {
    b = n2 * n4 - Math.sqrt(discriminant);
    b /= n1 * n1 + n2 * n2;
    fromLatRadians = Math.atan2(a, b);
  }
  if (fromLatRadians < -Math.PI / 2 || fromLatRadians > Math.PI / 2) {
    // No solution which would make sense in LatLng-space.
    return null;
  }
  var fromLngRadians = toRadians(to.lng) -
    Math.atan2(n3, n1 * Math.cos(fromLatRadians) - n2 * Math.sin(fromLatRadians));
  return new LatLng(toDegrees(fromLatRadians), toDegrees(fromLngRadians));
}
Returns the location of origin when provided with a LatLng destination,
meters travelled and original heading. Headings are expressed in degrees
clockwise from North. This function returns null when no solution is
available.
@param to       The destination LatLng.
@param distance The distance travelled, in meters.
@param heading  The heading in degrees clockwise from north.