Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

740
Views
How to get distance between two coordinates with Mapbox

I am learning how to use the Mapbox API for my node app and I want to perform calculations on the backend like getting the distance between two coordinates.

How can I achieve this?, the Mapbox documentation doesn't make this clear...

Set-up the SDK

const mapboxSdk = require("mapbox")
let mapbox = new mapboxSdk(process.env.MAPBOX_TOKEN)

// EXAMPLE OF WHAT I WANT TO DO

coordA = {lat : 33.968123, long: -118.419454}

coordB = {{lat : 33.997223, long: -117.929145}}

const distance = await mapbox.getDistance(coordA, coordB)

console.log(distance)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe Mapbox recommends using the Turf.js library for this type of thing: Turf.js Distance Function. However, the distance between two lat/long coords is a simple geometry problem that doesn't need any external APIs/libraries, and can be calculated from your coordinates using the Haversine Formula. Check this SO question for implementations of the Haversine formula as a javascript function.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!