Distance Calculations
Configure distance-based pricing using Google Maps integration.
Integrate Google Maps for Accurate Distance Calculations in WP Cost Estimation Forms
Learn how to set up and use distance calculations in your forms to provide accurate pricing based on travel distances.
Setting Up Distance Calculations
To utilize distance calculations in your forms, input a valid "Google Maps browser key" first. Obtain a JavaScript API key for Google Maps here: Get Google Maps API Key.
Required API Services
Activate these services in the Google API Console:
- •Distance Matrix API
- •Maps JavaScript API
- •Places API
- •Geocoding API
Configuring the API Key
Once you have your API key, enter it in the "Google Maps Browser Key" field in the General Settings tab of your form. This will enable the distance calculation features throughout your form.
Using Distance Calculations
Within the "Price & quantity" tab of your desired item, enable "Price calculation" or "Quantity calculation." Then, hit the "Add a distance" to access the distance calculation panel:
Distance Calculations Panel

Selecting Address Fields
Select the appropriate form fields for departure and arrival from dropdowns. If a field is absent, set the dropdown to "Nothing." The plugin detects available address fields using the "Type of information" option for text and select fields.
Distance Unit Selection
Decide whether the output should be in km or miles, then click "Insert".
Distance Calculation Modes
Use the "Distances calculation mode" setting under the "General" tab to specify if distances from the Google Maps API should be as "route" or "direct" travel.
Route Mode
Calculates the distance along roads and actual travel routes. This is more accurate for real-world travel distances and is recommended for most applications.
Direct Mode
Calculates the straight-line distance between two points (as the crow flies). This is useful for applications where direct distance is more relevant than travel distance.
Error Handling
In cases where Google Maps cannot calculate the distance, an editable error message will show (configurable in the "Texts" tab), and the form will not proceed until the user rectifies the input fields.
Customizing Error Messages
You can customize the error message that appears when a distance calculation fails. This is done in the "Texts" tab of the form settings. Look for the "Distance calculation error" field and enter your custom message.
Practical Examples
Delivery Cost Calculation
This sets a base price of $10 plus $0.50 per kilometer/mile of distance between the two addresses.
Travel Time-Based Pricing
This charges $2 per minute of travel time between the two addresses. The [duration-1-2] shortcode returns the travel time in minutes.
Conditional Pricing Based on Distance
This sets a flat rate of $20 for distances up to 10 km/miles, then adds $0.80 per additional km/mile beyond that.
Pro Tip: For businesses that offer services at customer locations, distance calculations can be a powerful tool to automatically adjust pricing based on travel distance. This ensures fair pricing while maintaining profitability for longer-distance services.