https://github.com/dastrobu/vincenty
Compute vincenty distance in Swift
https://github.com/dastrobu/vincenty
distance-calculation geodesic geodesics swift swift-4 swift-5 swift-library swift-linux vincenty
Last synced: 5 months ago
JSON representation
Compute vincenty distance in Swift
- Host: GitHub
- URL: https://github.com/dastrobu/vincenty
- Owner: dastrobu
- License: apache-2.0
- Created: 2018-03-31T22:21:26.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-01-08T21:44:16.000Z (over 2 years ago)
- Last Synced: 2026-01-03T07:46:47.700Z (5 months ago)
- Topics: distance-calculation, geodesic, geodesics, swift, swift-4, swift-5, swift-library, swift-linux, vincenty
- Language: Swift
- Homepage:
- Size: 59.6 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vincenty
[](https://swift.org)


Solver for the inverse geodesic problem in Swift.
The inverse geodesic problem must be solved to compute the distance between two points on an oblate spheroid, or
ellipsoid in general. The generalization to ellipsoids, which are not oblate spheroids is not further considered here,
hence the term ellipsoid will be used synonymous with oblate spheroid.
The distance between two points is also known as the
[Vincenty distance](https://en.wikipedia.org/wiki/Vincenty's_formulae).
Here is an example to compute the distance between two points (the poles in this case) on the
[WGS 84 ellipsoid](https://en.wikipedia.org/wiki/World_Geodetic_System).
import vincenty
let d = try distance((lat: Double.pi / 2,lon: 0), (lat: -Double.pi / 2, lon: 0))
To compute azimuths (also known as initial and final bearings)
let (d, (a, b)) = try solveInverse((lat: Double.pi / 2,lon: 0), (lat: -Double.pi / 2, lon: 0))
where `(a, b)` are the azimuths.
## Table of Contents
- [Installation](#installation)
- [Dependencies](#dependencies)
- [Swift Package Manager](#swift-package-manager)
- [Cocoa Pods](#cocoa-pods)
- [Implementation Details](#implementation-details)
- [Convergence and Tolerance](#convergence-and-tolerance)
- [WGS 84 and other Ellipsoids](#wgs-84-and-other-ellipsoids)
## Installation
### Dependencies
At least `clang-3.6` is required. On linux one might need to install it explicitly.
There are no dependencies on macOS.
### Swift Package Manager
```swift
let package = Package(
dependencies: [
.package(url: "https://github.com/dastrobu/vincenty.git", from: "1.1.2"),
]
)
```
## Cocoa Pods
Make sure a valid deployment target is setup in the Podfile and add
pod 'vincenty', '~> 1'
## Implementation Details
This is a simple implementation of Vincenty's formulae. It is not the most accurate or most
stable algorithm, however, easy to implement.
There are more sophisticated implementations, see, e.g.
[geodesic](https://github.com/dastrobu/geodesic).
## Convergence and Tolerance
Convergence and the accuracy of the result can be controlled via two parameters.
try distance((lat: 0,lon: 0), (lat: 0, lon: 0), tol: 1e-10, maxIter: 200)
## WGS 84 and other Ellipsoids
By default the
[WGS 84 ellipsoid](https://en.wikipedia.org/wiki/World_Geodetic_System)
is employed, but different parameters can be specified, e.g. for the
[GRS 80 ellipsoid](https://en.wikipedia.org/wiki/GRS_80).
try distance((lat: Double.pi / 2, lon: 0), (lat: -Double.pi / 2, lon: 0),
ellipsoid (a: 6378137.0, f: 1/298.257222100882711))
## Docs
Read the generated [docs](https://dastrobu.github.io/vincenty/documentation/vincenty/).