# Calculate Mileage with native Knack maps

**URL:** <https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093>\
**Category:** Ask Developers\
**Created:** [September 19, 2022, 8:26pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093 "2022-09-19T20:26:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/kyle/32/1555_2.png) [@Kyle](https://forums.knack.com/u/Kyle)\
**Post date:** [September 19, 2022, 8:26pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/1 "2022-09-19T20:26:49Z")

</div>

How do I calculate mileage from point a to point b using native Knack mapping?

---

<div class="post-metadata">

**Author:** ![CarlHolmes](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/carlholmes/32/2814_2.png) [@CarlHolmes](https://forums.knack.com/u/CarlHolmes)\
**Post date:** [September 19, 2022, 9:14pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/2 "2022-09-19T21:14:12Z")

</div>

No native way to do this in Knack.

This thread may be of interest:

> [@Total Mileage Calculation](https://forums.knack.com/t/total-mileage-calculation/7951/2):
>
> Thanks Alejandro, Now, I am studying your code and modified it a bit to come up with a minimalistic version of it in my Javascript pane (nothing else but this) : const MY\_GOOGLE\_API\_KEY = 'xxxxxxxxxxxxxx-yyyyyyyyyyyyyyyyyyyy'; const WORKSITE\_EDIT = 'scene\_145'; var googleMapsLoaded = $.Deferred(); window.googleMapsCallback = function () { googleMapsLoaded.resolve(); }; $.extend({ loadGoogleMaps: function () { $.ajax({ url: "https://maps.googleapis.com/maps/api/js…

Highly recommend reaching out to Alejandro Zakzuk @Soluntech

> **[Custom Software Development Services | Join Us | Soluntech](https://www.soluntech.com/)**
>
> Soluntech offers a wide range of full-stack, custom software development services, including low code app development. Let’s talk. Start your project today.

---

<div class="post-metadata">

**Author:** ![JulianKirkness](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/juliankirkness/32/770_2.png) [@JulianKirkness](https://forums.knack.com/u/JulianKirkness)\
**Post date:** [September 20, 2022, 9:00am UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/3 "2022-09-20T09:00:18Z")

</div>

Hi @Kyle - this is actually pretty simple to do with [Make](https://www.make.com/en/register?pc=kirkness) (formerly Integromat).

You set up a suitable trigger for your “Scenario” (Search, Updated or New Record etc) and then use the Google Maps module to calculate the distance for you. You can then update the same record with the result:

 ![Screenshot 2022-09-20 at 09.56.22](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/0/00d538da907d42735b62cb122e38c99f909c0adc.png)

You needs a Google Maps API account to do this - which is fairly straightforward to set up and then connect your Make module to that.

The advantage is that this is still a NO CODE solution!

---

<div class="post-metadata">

**Author:** ![Kyle](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/kyle/32/1555_2.png) [@Kyle](https://forums.knack.com/u/Kyle)\
**Post date:** [September 20, 2022, 12:12pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/4 "2022-09-20T12:12:28Z")

</div>

Carl,  
I read this last night and the way the thread ended seems like the original poster did not get it to work. I figured Knack would have a way to do in Here Map. I did not try the code you posted since I do not have a Google Map API code. Maybe I will have to try this. Have you used it?

---

<div class="post-metadata">

**Author:** ![CarlHolmes](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/carlholmes/32/2814_2.png) [@CarlHolmes](https://forums.knack.com/u/CarlHolmes)\
**Post date:** [September 20, 2022, 8:51pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/5 "2022-09-20T20:51:06Z")

</div>

Hi @Kyle - I’ve not had a use case for requiring mileage for an application yet. I’d recommend @JulianKirkness method as a no code approach is often easier.

---

<div class="post-metadata">

**Author:** ![Kyle](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/kyle/32/1555_2.png) [@Kyle](https://forums.knack.com/u/Kyle)\
**Post date:** [September 21, 2022, 6:00pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/6 "2022-09-21T18:00:15Z")

</div>

Thanks, Knack said to use Make. Trying out [Make.com](http://Make.com)

---

<div class="post-metadata">

**Author:** ![Kyle](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/kyle/32/1555_2.png) [@Kyle](https://forums.knack.com/u/Kyle)\
**Post date:** [September 22, 2022, 12:56pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/7 "2022-09-22T12:56:19Z")

</div>

Good day, Sir. I signed up Google Developer and got API key, copied this into Knack, enabled Google Map APIs that Knack suggested, signed up for Make and did what it says with Google. I got everyone connect, (i think) but I can not figure out how to build the Scenarios.  
Trying to pull Knack address data from the field, SHIP FROM and SHIP TO into Google, then use these fields to calculate miles from these to points, then Google or Make should update the same record with calculated mileage into the Transport Miles Field in Knack. Not sure what I am doing wrong.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/4/438b29383005dd6fc381eda6e784f6fc562b9fab.png)

Any help would be greatly appreciated.  
Kyle McAfee  
McAfee Trucking  
812-416-8964

---

<div class="post-metadata">

**Author:** ![JulianKirkness](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/juliankirkness/32/770_2.png) [@JulianKirkness](https://forums.knack.com/u/JulianKirkness)\
**Post date:** [September 23, 2022, 9:15am UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/8 "2022-09-23T09:15:12Z")

</div>

Hi Kyle

Looks as though you are getting the scenario triggered by a new record or update - which is fine as long as both origin and destination are completed. However, when you trigger a scenario in this way, the trigger module only returns the ID of the record. So…

1. After the New Event module, add a get record module and use the id from the new event to retrieve the record with the addresses in.

2. Update the Maps module to have the to and from fields from the get record module as the Origin and Destination - BUT turn off the ‘Map’ option for the Origin and Destination and add an ‘item’ to each like this:  

3. Add an Update Record module to take the results from the map module and update your Distance field:  

The arrow shows the value you need to select (if you want miles) - the other option is in metres I think.

This should then complete the process. One thing to warn you about is that the Maps module will give an error if either of the address fields are empty - so you should maybe add a filter before to stop the scenario if either are blank.

Hope this helps.

Julian

---

<div class="post-metadata">

**Author:** ![Dkeoc](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Dkeoc](https://forums.knack.com/u/Dkeoc)\
**Post date:** [January 6, 2025, 2:17pm UTC](https://forums.knack.com/t/calculate-mileage-with-native-knack-maps/13093/9 "2025-01-06T14:17:13Z")

</div>

To calculate mileage with native Knack maps, you can integrate the mapping feature directly into your project. This allows for easy distance calculation between different locations. For more details on customizing software and adding such features, you can check out this link: [https://www.cleveroad.com/blog/custom-software-development/](https://www.cleveroad.com/blog/custom-software-development/).
