简体   繁体   中英

calculating heading from latitude and longitude in excel

我想在 excel 中用 P1(lat1 , long2) 和 P2(lat2 long2) 计算 2 个点之间从北方的航向方向。

It depends on what level of accuracy you are looking for. Haversine formula is simple yet may be insufficient since it assumes Earth surface is a perfect sphere (which it is not) and provides only limited accuracy.
Vincenty's formulae provide way better, geodesic grade accuracy (1.46E-6 degrees).
VBA Excel implementation I put together can be found on GitHub: https://github.com/tdjastrzebski/Vincenty-Excel .
VincentyInvFwdAzimuth() function should get you what you need.

I have a function used for ham radio calculations. A "pure" formula was too bulky for me.

Function BearingFromCoord(lat_base_deg, long_base_deg, lat_dest_deg, long_dest_deg As Single) As Long
   Dim rad_deg_factor As Single
   Dim long_diff As Single
   Dim frac0 As Single
   Dim frac1 As Single
   Dim frac2 As Single
   Dim lat_base As Single
   Dim long_base As Single
   Dim lat_dest As Single
   Dim long_dest As Single
   Dim bearing As Single

   rad_deg_factor = 360 / (2 * pi())

   long_diff = (long_base_deg - long_dest_deg) / rad_deg_factor
     lat_base = lat_base_deg / rad_deg_factor
       lat_dest = lat_dest_deg / rad_deg_factor
          frac0 = Sin(lat_base) * Sin(lat_dest) _
              + Cos(lat_base) * Cos(lat_dest) _
                * Cos(long_diff)
             bearing = rad_deg_factor * Application.WorksheetFunction.Acos((Sin(lat_dest) _
                        - Sin(lat_base) * frac0) _
                    / (Cos(lat_base) * Sin(WorksheetFunction.Acos(frac0))))
          If Sin(long_diff) < 0 Then
            BearingFromCoord = bearing
          Else
            BearingFromCoord = 360 - bearing
          End If
End Function

Private Function pi() As Single
  pi = 3.1415926535
End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM