Google Maps API and Tape

Google Maps API and Tape

October 23, 2023

6 minutes read

Recently, a fellow Tape Partner, John(1F2Ns), posted on the community forums (an excellent place to visit if you are interested in Tape and what it can do) asking if anyone had built a solution to get the distance between two locations from the Google API in Tape.

Although I hadn’t, it got me thinking about all the possible use cases and benefits for small to medium businesses; the most obvious being a mileage expense claim/log. I felt it was worth a look on a rainy Saturday, so I dived head-first down the rabbit hole. Anyway, I emerged a few hours later with what I feel is a good example of how it could work.

Part One

If you just want an example of it working, then this first part is for you. It can obviously be adapted to a number of different scenarios. Another example could be a transport planning app where you pull in addresses through a relationship to your client’s app.

gif of the app working

In the demonstration above, you simply fill in the two location fields, save the record, hit the ‘get mileage’ button (the button could be removed so it happens automatically on record creation), and off it goes to Google, asking for the distance between the two locations. It takes the response, adds it to the record, does a quick calculation to get the claim amount, and generates a title from the data.

(you can see a video here if thats more useful)

Ideally, for a full system, other workflows would be added for routing, notification, etc. and should also reference the user.

Part Two

In Part Two, we will get more into the technical aspects of achieving Part One. So, if you’re interested in building this yourself, read on. If the term ‘API’ lost you, reach out to us here and we can talk about how we can help you.

Stage One

You need a Google account linked to an API key that has access to the Google Maps system. This is very easy to set up, and Google takes you through it better than I can. I started on this page and went from there. You are likely to need a credit card, as Google uses it as a check against bots, etc. There are also potential costs associated with using the Google service, so make sure you are aware of these and comfortable before you move forward.

You should now have your valid API key so we can move on to the next step.

Stage Two

For the rest of this, we will be in Tape. If you don’t already have a Tape account, grab one here. This is not an affiliate link, but if someone from Tape asks, mentioning us would be great ;)

I’m going to assume you can work out how to create a new Workspace and App. If you can’t, that’s fine, but honestly, you probably should go back up to the top of Part Two and click the link to get in touch with us.

So set up an app with fields similar to the ones we have. Remember, you will need to change any differences in the next stage as well.

The other option is to click here and you will get sent a link to download a template with the complete demo (you will still need to add your Google API key).

Stage Three

The workflow is going to look similar to this:

image of workflow

So let’s get started. Top right of your screen, click the lightning bolt and then click ‘Create new automation.’

We will make this an on-update trigger.

Stage Four

We will now explain each step:

  1. You need to enter your API key and this is where you do that. I store all my API Keys in a separate app but you can just copy and paste yours into this calculation field and it will work fine:

    Calculation field for API Key

  2. This is another calculation field, and it gets the start point from the record’s “start location” field and uses encodeURIComponent to encode the location ready to send. Make sure the names match your setup. If the part in the ‘( )’ is not blue, it won’t work:

    Calculation field showing encoding of location

  3. This third calculation field does the same but for the end location:

    End Location

  4. Now that we have our encoded locations, we can start building the request we are going to send to Google. It is quite a simple request based around the two locations. One thing to be aware of is that the destination is first with the start location second. Where I have put ‘imperial’, that is telling Google to give me the distance in miles instead of kilometres. Now when Google sends back the response, it does so in two parts: a text part and a Value:

value json

The ‘imperial’ option only changes the text part not the value, which remains in metres always. Therefore if you want kilometres rather than miles, you can either leave the imperial option out or perform your calculation on the Value and convert it into kilometres. The last part of the request is your API key pulled from the first calculation field:

The request

  1. The next bit adds our response to the google URL ready to send it out to Google. Why do I put my request variable on the URL line rather than in the nice ‘request’ box underneath? Honestly, I don’t know - it works for me though and as I build the request higher up, it doesn’t get messy:

    URL

  2. Google will send back a response which will look something like:

full response

This next calculation field goes into that and just pulls out the bit we want, which in this example would be 228 mi - which is great, but still not too much help. But we fix that in the seventh step:

Before we move on though you may remember that above I said that if you wanted your result in kilometres you could use the value key instead and just convert that from metres to KM:

get the distance

This should give you the 367654 ready to be divided by 1000 to become 367.65 km

  1. The very last calculation field takes your 228 mi and splits it and then takes the 228 part; however, it is still a string and we really want a numeric value so that we can put it in a number field and run calculations on it later:

convert to number

  1. The final part of this automation is to update the record with the data we have gathered. In the screenshot below, you can see I make 4 updates to the record. We only really need to make one: the second down. The other three are there for debugging really so that you can see what is going on, and these could be removed once you are happy.

    Updating the record

Conclusion

Congratulations! You’ve now successfully set up a working demo and gained insight into seamlessly integrating Google Maps API with Tape. In summary, here’s what we’ve accomplished:

  1. Crafted a request sent to Google.
  2. Processed the response, extracting the crucial data.
  3. Fine-tuned the information to fit our desired format.
  4. Updated our Tape record, providing the foundation for future calculations and workflow triggers. And all of this achieved effortlessly through a Tape Automation. Keep innovating with Tape!

Get in touch with us today to explore how we can tailor this integration to suit your specific needs.

Your privacy matters to us. We'll use your information to respond to your message and provide the assistance you need. Occasionally, we may reach out with relevant updates. By clicking 'Send', you agree to our use of your data for these purposes. You can unsubscribe at any time. For more details, review our Privacy Policy

Maximizing Efficiency: Integrating Tape with OpenAI

April 10, 2024

Maximizing Efficiency: Integrating Tape with OpenAI

In this blog post, we delve into the transformative power of integrating Tape with OpenAI. From enhancing note quality to streamlining workflow automation and fostering innovative idea generation, we explore how this integration revolutionizes knowledge management. Discover how businesses can unlock unparalleled efficiency and productivity by harnessing the combined capabilities of Tape and OpenAI.

Streamlining Marketing URLs: A Tape-Powered Solution

September 28, 2023

Streamlining Marketing URLs: A Tape-Powered Solution

Revolutionize your marketing efforts with our Tape-powered UTM URL solution. Streamline link management, track performance, and create branded short links effortlessly. Take the first step towards efficient marketing workflows today!

Tips on Password Management and Security

September 18, 2023

Tips on Password Management and Security

Explore effective strategies for password management and security in our latest blog. Discover the power of password managers like 1Password, ProtonPass, and Nordpass, and learn about the 'Three Random Words' technique recommended by the UK National Cyber Security Centre. Elevate your digital security today.