This also improves accuracy for small distances, using the haversine distance formula instead of the law of cosines. Fixes #1080.