Loading...

Your privacy choices

Google Analytics 4 measures site visits and Google Ads measures advertising clicks and checkout completions, only for the purposes you accept. Neither is required to buy. Necessary checkout services remain available.

Your privacy choices

Google Analytics 4 measures site visits and Google Ads measures advertising clicks and checkout completions, only for the purposes you accept. Neither is required to buy. Necessary checkout services remain available.

These optional Google services may set audience or advertising cookies after your acceptance. Analytics and advertising are separate choices. Acceptance and refusal are remembered in this browser for a fixed 180 days, without extending the period when read. You can withdraw or change your choices at any time using Privacy choices in the footer. Withdrawal removes optional first-party Google cookies and reloads the page if Google has already loaded (using session storage in this tab if persistent storage refuses the withdrawal; a blank page opens only if both stores cannot safely record the withdrawal and a stale approval remains). Checkout, external demos, videos, support and newsletter services have their own privacy information.

Complete Documentation

Documentation

Everything you need to know about WP Cost Estimation

Distance Calculations

Section 14•5 min read

Configure distance-based pricing using Google Maps integration.

Available in Pro and Agency.

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
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
[price] = 10 + ([distance-1-2] * 0.5)

This sets a base price of $10 plus $0.50 per kilometer/mile of distance between the two addresses.

Travel Time-Based Pricing
[price] = [duration-1-2] * 2

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
[price] = 20 if([distance-1-2] > 10) { [price] = 20 + (([distance-1-2] - 10) * 0.8) }

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.

Keep moving

Useful next steps from documentation