Shipping Costs Based on Distance

Version v1.9.0
Platform Magento 2
Last Updated 8 January 2026

Setup Google Maps API for Distance Shipping

Looking for Magento 2 distance-based shipping extension? View the full Magento 2 distance-based shipping extension page to explore features, configuration options, and pricing.

Configure your Google Maps API key for the Shipping Costs Based on Distance extension. This guide walks you through creating a Google Cloud project, enabling the required APIs, and setting up your credentials.

Required API

This extension supports two Google Maps APIs:

  1. Routes API (Recommended) - The new API with improved performance and features
  2. Distance Matrix API (Legacy) - The older API for backward compatibility

You can select which API to use in the configuration panel. Both APIs calculate travel distances between your store location and customer addresses.

For New Installations: We recommend using the Routes API.

For Existing Installations: Your installation will continue using Distance Matrix API by default. You can migrate to Routes API at your convenience by enabling it in Google Cloud Console and switching the configuration.

Step 1: Create a Google Cloud Project

  1. Go to Google Cloud Console
  2. Sign in with your Google account
  3. Click the project dropdown at the top of the page
  4. Click New Project
  5. Enter a project name (e.g., "Magento Shipping")
  6. Click Create
  7. Wait for the project to be created, then select it

Step 2: Enable Billing

Both Google Maps APIs require a billing account. Google provides $200 free credit per month.

  1. Go to Billing in the left menu
  2. Click Link a billing account
  3. Follow the prompts to set up billing
  4. Add a payment method

Note: You won't be charged unless you exceed the free tier limits.

Step 3: Enable the API

Choose which API to enable based on your preference:

  1. Go to APIs & Services → Library
  2. Search for "Routes API"
  3. Click on Routes API
  4. Click Enable

Option B: Distance Matrix API (Legacy - for existing installations)

  1. Go to APIs & Services → Library
  2. Search for "Distance Matrix API"
  3. Click on Distance Matrix API
  4. Click Enable

Note: You can enable both APIs if you want to test migration between them.

Step 4: Create API Key

  1. Go to APIs & Services → Credentials
  2. Click + Create Credentials
  3. Select API key
  4. Your new API key will be displayed
  5. Click Copy to copy the key
  6. Click Close

Protect your API key from unauthorized use:

  1. In the Credentials page, click on your API key name
  2. Under Application restrictions:
    • For testing: Select None
    • For production: Select IP addresses and add your server IP
  3. Under API restrictions:
    • Select Restrict key
    • Check the API you're using:
      • Routes API (if using the new API)
      • Distance Matrix API (if using the legacy API)
      • You can check both if you want to test migration
  4. Click Save

Step 6: Configure in Magento

  1. Go to Magmodules → Shipping Costs Based on Distance
  2. Under General → API and Location Details:
    • Google Maps API Version: Select which API to use
      • Routes API (Recommended) - Use the new Routes API
      • Distance Matrix API (Legacy) - Use the legacy API (default for existing installations)
    • Paste your API key in the API Key field
    • Enter your Store Address (full address including country)
  3. Click Test Credentials to verify the connection
  4. Click Save Config

Important: Make sure the API version you select matches the API you enabled in Google Cloud Console.

API Pricing

Google charges per request. Pricing varies by API:

Monthly free credit: $200

Pricing may vary by region and usage tier. The Routes API generally offers better performance and may have different pricing tiers than the legacy Distance Matrix API.

When are requests made?

  • When a customer enters/changes their shipping address at checkout
  • When using the product page shipping estimator
  • During selftest/credential testing

Monitoring Usage

Track your API usage to manage costs:

  1. Go to APIs & Services → Dashboard
  2. Click on the API you're using:
    • Routes API (if using the new API)
    • Distance Matrix API (if using the legacy API)
  3. View the Traffic chart for request counts
  4. Check Errors for any failed requests

Set Up Billing Alerts

  1. Go to Billing → Budgets & alerts
  2. Click Create Budget
  3. Set a budget amount
  4. Configure alert thresholds (e.g., 50%, 90%, 100%)
  5. Add notification email addresses

Store Address Best Practices

The store address you enter is the origin point for all distance calculations.

Do:

  • Use your warehouse or fulfillment center address
  • Include full address: street, city, postal code, country
  • Use the address format Google Maps recognizes

Examples of Good Addresses:

123 Warehouse Street, Amsterdam, 1012 AB, Netherlands
456 Distribution Center Dr, Rotterdam, 3011 BC, NL

Don't:

  • Use PO Box addresses
  • Use incomplete addresses
  • Use addresses Google can't find

Testing Your Setup

After configuration, verify everything works:

  1. Test Credentials Button

    • Click the button in configuration
    • Should show success message
  2. Selftest Command

    • Run: bin/magento distancebasedshipping:selftest
    • Checks API connectivity and configuration
  3. Checkout Test

    • Add a product to cart
    • Go to checkout
    • Enter a shipping address
    • Verify distance-based shipping option appears

Troubleshooting API Issues

"API key not valid"

  • Verify the key is copied correctly (no extra spaces)
  • Check the key is enabled in Google Cloud Console
  • Ensure the correct API is enabled for the project (Routes API or Distance Matrix API)
  • Verify the API version setting in Magento matches the API enabled in Google Cloud Console

"This API project is not authorized"

  • Enable the appropriate API in your project (Routes API or Distance Matrix API)
  • Ensure the API version in Magento configuration matches what's enabled in Google Cloud Console
  • Wait a few minutes after enabling for changes to propagate

"You have exceeded your daily request quota"

  • Check your usage in Google Cloud Console
  • Upgrade your billing plan if needed
  • The free tier resets monthly

"REQUEST_DENIED"

  • Check API key restrictions aren't blocking your server
  • Verify billing is set up correctly
  • Ensure the API is enabled

"ZERO_RESULTS"

  • Store address may not be recognized by Google
  • Try a more specific address format
  • Test the address in Google Maps first

Need More Help?

Documentation:

Support:

Google Resources:

For a complete overview of features and configuration options, see Magento 2 distance-based shipping extension.

Article Updated:
Download PDF
star star star star star
star star star star star
Gaaf - digital agency
We have tried the integration with SnelStart through several different providers, and this is the only solution that simply works. We needed support on two occasions, and it was provided quickly and professionally. We do recommend this company!
Google 12 May 2026
star star star star star
star star star star star
Andrew Velikiy
Great vendor with handy modules and quick support!
Google 13 Apr 2026
star star star star star
star star star star star
Alexandru-Manuel Carabus
Magmodules sets the bar for Magento module quality and support—we check their catalog first for client feature requests, and they’re our first choice for licenses.
Google 11 Nov 2025
star star star star star
star star star star star
Matt Austin
Possibly the fastest support response times of any Magento Extension vendor. Great extensions too!
Google 09 Sep 2025
star star star star star
star star star star star
Jan Privé
Dankzij de heldere uitleg en snelle reactie van Magmodules kon mijn vraag, en dus mijn Magento-probleem, binnen enkele uren worden beantwoord. Doeltreffend, zonder moeilijke termen, gewoon zo als het zou moeten zijn.... Bedankt!
Google 05 Sep 2025
star star star star star
star star star star star
Denis Metzler
To evaluate a provider, it is not enough to consider only the product offered, but also its after-sales service, such as support and troubleshooting. Magmodules has been extremely satisfactory at all levels on multiple occasions and sets the bar at the top when comparing the competition.
Google 02 Sep 2025
star star star star star
star star star star star
Bleijenberg winkelinrichting en materialen
Goed bereikbaar, reageren snel en denken oplossingsgericht. Een aanrader.
Google 30 Jul 2025
star star star star star
star star star star star
Patrick Verduijn
Magmodules biedt plugins aan die van hoge kwaliteit zijn tegen een goede prijs, waar dit bedrijf in uitblinkt is de bereidheid om de zeldzame feedback & problemen met de plugins te willen onderzoeken, mee te willen denken in het debuggen van problemen en goede oplossingen toe te passen. In mijn decennium ervaring met Magento & 3th parties is Magmodules absoluut een uniqum binnen de markt.
Google 25 Jul 2025
star star star star star
star star star star star
Erik de Groot
Magemodules heeft hele sterke Magento extensies en een proactieve support. Al jaren heel erg tevreden over jullie service en producten!
Google 18 Jul 2025
star star star star star
star star star star star
René Zeuner
We are using the Mollie Magento extension from Magmodules. It works excellently without flaws. Very fast, competent and friendly support. Thanks!
Google 30 Jun 2025