{"id":13482261,"url":"https://github.com/geocrystal/haversine","last_synced_at":"2026-02-25T20:30:54.250Z","repository":{"id":66224788,"uuid":"185599171","full_name":"geocrystal/haversine","owner":"geocrystal","description":"Crystal implementation of the Haversine formula to calculate distances between two points given their latitudes and longitudes","archived":false,"fork":false,"pushed_at":"2025-11-24T09:06:36.000Z","size":896,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-27T21:43:50.941Z","etag":null,"topics":["crystal","haversine-formula"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geocrystal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-08T12:12:43.000Z","updated_at":"2025-11-24T09:05:26.000Z","dependencies_parsed_at":"2024-04-30T10:46:30.921Z","dependency_job_id":"01a1ab7b-87c9-4331-a846-ad618ad5e94b","html_url":"https://github.com/geocrystal/haversine","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/geocrystal/haversine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geocrystal%2Fhaversine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geocrystal%2Fhaversine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geocrystal%2Fhaversine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geocrystal%2Fhaversine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geocrystal","download_url":"https://codeload.github.com/geocrystal/haversine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geocrystal%2Fhaversine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29838027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T19:08:47.527Z","status":"ssl_error","status_checked_at":"2026-02-25T18:59:04.705Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","haversine-formula"],"created_at":"2024-07-31T17:01:00.377Z","updated_at":"2026-02-25T20:30:54.231Z","avatar_url":"https://github.com/geocrystal.png","language":"Crystal","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"# haversine\n\n[![Crystal CI](https://github.com/geocrystal/haversine/actions/workflows/crystal.yml/badge.svg)](https://github.com/geocrystal/haversine/actions/workflows/crystal.yml)\n[![GitHub release](https://img.shields.io/github/release/geocrystal/haversine.svg)](https://github.com/mamgeocrystalantoha/haversine/releases)\n[![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://geocrystal.github.io/haversine/)\n[![License](https://img.shields.io/github/license/geocrystal/haversine.svg)](https://github.com/geocrystal/haversine/blob/master/LICENSE)\n\nCrystal implementation of the [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula) to calculate distances between two points given their latitudes and longitudes.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     haversine:\n       github: geocrystal/haversine\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"haversine\"\n```\n\n### Distance\n\nCalling `Haversine.distance` with four latitude/longitude coordinates returns a `Haversine::Distance` object which can provide output in kilometers, meters, miles, feet, or nautical miles.\n\nEach \"coordinates\" member **must** be a pair of coordinates - `latitude` and `longitude`.\n\n`Haversine.distance` accepts of either:\n\n- `Haversine.distance(lat1, lon1, lat2, lon2)`\n- `Haversine.distance({lat1, lon1}, {lat2, lon2})`\n- `Haversine.distance([lat1, lon1], [lat2, lon2])`\n\n```crystal\n# Tokyo -\u003e Paris\ndistance = Haversine.distance(35.61488, 139.5813, 48.85341, 2.3488)\n\ndistance.to_kilometers     # =\u003e 9715.470491159029\ndistance.to_meters         # =\u003e 9715470.491159027\ndistance.to_miles          # =\u003e 6032.710918698025\ndistance.to_feet           # =\u003e 31852713.65072557\ndistance.to_nautical_miles # =\u003e 5242.2799481204265\n```\n\nIf you have latitude/longitude pairs stored in an array or tuple, you can alternately provide two arrays/tuples when calling `Haversine.distance`:\n\n```crystal\nlondon = [51.500153, -0.126236]\nnew_york = [40.714268, -74.005974]\n\ndistance = Haversine.distance(new_york, london)\ndistance.to_kilometers # =\u003e 5570.482153929098\n\nlondon = {51.500153, -0.126236}\nnew_york = {40.714268, -74.005974}\n\ndistance = Haversine.distance(new_york, london)\ndistance.to_kilometers # =\u003e 5570.482153929098\n```\n\n![haversine](/assets/readme_image.png)\n\n\u003chttps://www.movable-type.co.uk/scripts/latlong.html\u003e\n\nAlso you can compare `Haversine::Distance` objects:\n\n```crystal\nlondon = [51.500153, -0.126236]\nnew_york = [40.714268, -74.005974]\nshanghai = [31.222220, 121.458060]\n\ndistance1 = Haversine.distance(london, new_york)\ndistance2 = Haversine.distance(london, shanghai)\n\ndistance1 \u003c distance2 # =\u003e true\n```\n\n### Destination\n\nTakes the starting point by `latitude`, `longitude` and calculates the location of a destination point\ngiven a `distance` factor in degrees, radians, miles, or kilometers; and `bearing` in degrees.\n\n```crystal\nHaversine.destination(39, -75, 5000, 90, :kilometers)\n# =\u003e {26.440010707631124, -22.885355549364313}\n```\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/geocrystal/haversine/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Anton Maminov](https://github.com/mamantoha) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeocrystal%2Fhaversine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeocrystal%2Fhaversine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeocrystal%2Fhaversine/lists"}