Stay Ahead in Ruby!
From development processes to the most useful gems, get it all straight in your inbox. Join our Ruby blog today!

Skip to main content

Comparative Analysis of Distance Calculation Systems

comparison-of-distance-calculation-methods - cover image

Top Systems for Distance Calculation: What’s Used Most? #

In this article, a comparative analysis of various distance calculation methods and technologies is conducted, aiming to provide insights into their respective strengths, weaknesses, and suitability of these methods and technologies for different use cases.

Among the methodologies and services under examination are the most widely used systems:

  1. Mapbox Directions API
  2. TomTom API
  3. Google Maps Directions API
  4. Haversine Formula
  5. Manhattan Formula
  6. OpenStreetMap (OSRM)

These the most popular technologies and methods play crucial roles in determining distances between geographical points, with applications spanning logistics, transportation, navigation, and beyond.

Pros and Cons of Systems #

System Type Advantages Disadvantages
Mapbox Directions API External API • Provides high-quality maps and data;
• wide range of tools
• May have request number limits
TomTom API External API • Provides extensive road network data;
• high reliability
• May have request number limits
Google Maps Directions API External API • Wide functionality;
• high reliability;
• extensive developer community
• Paid service;
• may have request number limits;
• dependency on integration with other Google services
Haversine Formula Geodesic • Accurately accounts for Earth’s curvature;
• suitable for long distances;
• more suitable for calculating distances between 2 points
• Does not account for road conditions;
• may be less efficient for city streets
Manhattan Formula Algorithmic • Simple implementation;
• suitable for city streets;
• more suitable for calculating distances between 2 points
• Does not account for geographical features;
• does not account for road conditions
OpenStreetMap (OSRM) External API • Free and open-access data for use;
• extensive community;
• community-driven updates
• Not always up-to-date with current data;
• may be less reliable in certain regions
In addition, Haversine Formula is used in Ruby gems such as Geokit, Geocoder, Haversine etc.

Selecting the Best Distance Calculation System for Your Needs #

  • Mapbox API - ideal for highly adaptable and cost-efficient mapping solutions, offering customizable layers and precise control over visual elements. It’s well-suited for developers who prioritize custom mapping solutions and flexible integration;
  • TomTom API - best for logistics software requiring robust pre-built layers, dependable coverage, and efficient routing algorithms. Especially useful for fleet management and asset tracking;
  • Google Maps API - perfect for logistics software seeking comprehensive global traffic data, extensive customization capabilities, and seamless integration with various Google services;
  • Haversine Formula - ideal for calculating distances between two points on Earth’s surface, accounting for its curvature;
  • Manhattan Formula - best for calculating distances within urban areas where streets follow a grid pattern;
  • OpenStreetMap (OSRM) - suitable for projects where cost-effectiveness and community collaboration are crucial, offering easy integration with various tools and applications.

Comparison of the basic characteristics #

Criteria Mapbox API TomTom API Google Maps API Haversine Formula Manhattan Formula OpenStreet Map
Price Free (before 100000 requests per month) / Paid Free (before 2500 requests per day) / Paid Paid Free Free Free
Real-time Yes Yes Yes No No No
Accuracy High High The highest Low Low Medium
Customization Yes / The highest Yes / Low Yes / High No No Yes / High
Street view Yes / High Yes / Medium Yes / The highest No No Yes / High
Data updates Regular Sometimes Regular None None Regular
Ease of integration Medium Medium Medium Simple Simple Simple
Documentation Excellent Good Excellent Limited Limited Good
Speed High High High Medium Low Medium
Community Support High Medium High Low Low High

Point-to-Point Distance Comparison: Which Method Reigns Supreme? #

System Distance < 1 mile Distance ≈ 2 miles Distance ≈ 3 miles Distance > 1000 miles
Mapbox Directions API 0.7 2.2 3.5 1174.3
TomTom API 0.7 2.1 3.29 943.24
Google Maps Directions API 0.7 2.1 3.3 1050
Haversine Formula 0.48 1.5 2.79 829.19
Manhattan Formula 0.66 1.7 2.99 1067.1
OpenStreetMap (OSRM) 0.68 1.99 3.23 1098.58

Keep in mind that these settings were chosen for distance calculations:

  • the city is Austin (USA);
  • cycling as travel modes;
  • traffic was not taken into account;
  • the shortest route offered by the system.

Based on the comprehensive comparison of point-to-point distance calculation methods, several key observations emerge.

In general, for shorter distances of approximately 1 mile or less, the Manhattan Formula consistently offers the most accurate results, closely followed by the Haversine Formula. These systems are free and easy to integrate and are suitable for a small system whose goal is to calculate short distances between 2 points.

However, as distances increase, the Google Maps Directions API consistently outperforms other systems, demonstrating remarkable accuracy even for distances exceeding 1000 miles. While the TomTom API and Mapbox Directions API exhibit competitive performance across various distance ranges, they slightly lag behind Google Maps for longer distances. OpenStreetMap (OSRM) provides reliable results, particularly for mid-range distances, although it falls slightly short compared to the top-performing systems at extreme distances.

Ultimately, the choice of method should be tailored to the specific requirements of the application, considering factors such as distance range, computational efficiency, and level of accuracy required.

Choosing the Right Distance Calculation System: A Quick Guide #

Finding the optimal system for calculating distances involves considering various factors to align with your specific needs and circumstances. Here’s a guide to help you navigate through the selection process:

%%{ init: { 'theme': 'forest', 'themeVariables': { 'fontSize': '26px', 'lineColor': '#F8B229' } } }%% graph TD A{{Project Requirements}} --> B{{Consider Project Region}} B --> C{{Project Budget}}
  • Consider Project Requirements: Identify the key features and functionalities you require from the distance calculation system. Consider whether you need features such as street view, offline mode, or advanced customization options. Understanding your specific needs will help narrow down your options and choose a system that best suits your requirements.

  • Consider Project Region: Take into account the geographic region where you’ll be using the system. Different regions may have unique challenges, such as limited availability of real-time traffic data in certain areas. For example, in regions like Asia, South America, or Africa, tracking traffic in real time might be more challenging compared to regions with well-established infrastructure and data coverage. In such cases, opting for globally recognized services like Google Maps or leveraging local services may provide more accurate and reliable data.

  • Project Budget: Consider your budgetary limitations when selecting a distance calculation system. While Google Maps offers extensive features and functionalities, it’s also known to be relatively expensive. In addition to paying for access to the platform, there may be additional costs associated with custom layers or advanced features. Evaluate the cost-effectiveness of each option and choose a system that aligns with your budget while still meeting your requirements.

By carefully considering these factors, you can make an informed decision and choose the right system for calculating distances that meets your needs, budget, and geographical considerations.

We are ready to provide expert's help with your product
or build a new one from scratch for you!

Contact MobiDev’s tech experts!
MobiDev Ruby Team
Yuliia Kirichenko
Ruby Developer at MobiDev. Hands-on experience in implementing complex business logic from scratch, optimizing and improving security.

comments powered by Disqus