mapbox / cheap-ruler

Fast approximations for common geodesic measurements 🌐
https://www.mapbox.com/blog/cheap-ruler/
ISC License
418 stars 32 forks source link

Adding an option to use GeoPoint objects as input #40

Closed EskelCz closed 5 years ago

EskelCz commented 5 years ago

@mourner Thanks for this library, I love it. :) But I have a slight issue with its integration into my project. Most other geolocation libraries I'm using are storing location data as an object, in this format: { latitude: Number, longitude: Number } For example Google Firestore is using such format: https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/GeoPoint

So I'd like to modify cheapRuler to use this format as well, to keep my code clean.

My question is, would that be something that you would support? Is so, how would you go about the implementation? So I can do it correctly and open a PR. Otherwise I will just create a fork where I simply change the format a post a link here.

mourner commented 5 years ago

[lng, lat] is the most widely used standard for locations in JavaScript because it's a part of the GeoJSON specification. If you have your data in a different format, converting to GeoJSON coordinates is trivial:

const convert = ({latitude, longitude}) => [longitude, latitude];
const distance = ruler.distance(convert(a), convert(b));
EskelCz commented 5 years ago

Well I know it's trivial, it just looks a bit messy. Here's the fork for anyone who wants the object data format. https://github.com/EskelCz/cheap-ruler