How to calculate the distance between two adress directly in server action

Hello, I have a list of technicians and a list of customers, I would like to display the nearest technician. for this I wanted to know if in Server Connect I can use the Google API to calculate this distance and store it in my database?

thanks in advance

Do you want the distance by road or the actual distance in a straight line

The former needs the google API, the latter can be calculated by a formula not incurring any google charges

by the way, I have to call the google api but not directly from the google map module of appconnect because I don’t have it in serverconnect

If you know the coordinates of the start and end points you can calculate the distance between with an equation in a custom query but it returns the geographical distance, not the road travel distance

I found the code for the API, the result is in the response, but how can I retrieve the response in order to store it in my database

https://maps.googleapis.com/maps/api/distancematrix/json?destinations=9%20rue%20la%20parra%2012450%20luc%20la%20primaube&origins=738%20route%20des%20devezes%2012850%20onet%20le%20chateau%20%20&units=imperial%20%20&key=**********************

when inserting a new technician I could thus record the distance with each customer

Hey Morgan

You can use the Api action, check this topic from Max


Please note that too many request can means a lot of charges due to the cost of the maps api usage, check the google docs and be sure to use it wisely.

Hi Brian!

I remember trying something that you’ve mention in a post from years ago, but no luck, still working? Never got it running :frowning_face:

I gues this is the best approach as you can avoid the cost of the api

No twason why it shouldn’t work, it’s not reliant on other factors,it’s just an equation

Hi, My soluce in serverconnect :

I first encode the addresses in order to retrieve the latitude and longitude of my two addresses which I will store in my database. Afterwards I call my Google Matrix API to determine the duration of the journey and the number of kilometers. The hardest part was filtering the response, so I’ll let you see how I did it, it will be useful to others.

1 Like