Shipping Costs Based on Distance

Version v1.8.2
Platform Magento 2
Released 4 November 2025

Google Maps API Setup Guide for Magento 2

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

The extension requires the Distance Matrix API from Google Cloud Platform. This API calculates travel distances between your store location and customer addresses.

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

The Distance Matrix API requires 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 Distance Matrix API

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

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 Distance Matrix API
  4. Click Save

Step 6: Configure in Magento

  1. Go to Magmodules → Shipping Costs Based on Distance
  2. Under General → API and Location Details:
    • 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

API Pricing

Google charges per request to the Distance Matrix API:

Tier Price per 1,000 requests
0 - 100,000 $5.00
100,001 - 500,000 $4.00
500,001+ Contact Google

Monthly free credit: $200 (covers ~40,000 requests)

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 Distance Matrix 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 Distance Matrix API is enabled for the project

"This API project is not authorized"

  • Enable Distance Matrix API in your project
  • 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:

Created:
Updated:
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
star star star star star
star star star star star
R. U.
Erg goed team, reageren snel en duidelijk en hebben met toegang tot onze database erg goed geholpen (eigenlijk een gratis customization).
Google 18 Jun 2025
star star star star star
star star star star star
Hugo de Groot
Uitstekende support! Wij gebruiken o.a. de Rich Snippets Suite extensie voor onze Magento 2 webshop (Hyvä) en hadden een specifieke vraag over structured data op PLP-pagina’s. Binnen no-time kregen we een inhoudelijk en duidelijk antwoord. Zeer prettig contact en goed onderbouwde uitleg. Absoluut een betrouwbare partner voor Magento-extensies!
Google 13 Jun 2025