FileMaker Google Route Optimization
Whether you are a technician that has multiple appointments in a day, or you are a traveling salesperson, you want to minimize your time on the road. Luckily for us, Google has an API for route optimization! Let’s look at how to connect your FileMaker solution with the Google Maps Directions API to take a list of locations and order them to minimize the time spent traveling.
Creating a Free Developer Account
Getting your API key is free and easy, and the first step is to create a project in the Google Developers Console if you don’t already have one.
You can get away without using an API key, but you will be limited to 8 locations. Once you have created the project, you will then need to enable the Google Maps Directions API and then set up the credentials for the API. This will take you to a setup process where the API will be managed. We will be using HTTP requests, so you will want to mark that the API will be accessed via a web browser client.
Once you have created your credentials, and the API Key has been created, copy it into your solution. Now you have everything you need to make requests to the Google Directions API.
Making Requests and Parsing the Response
The request to the Google Maps Directions API can be completely handled by using the native FileMaker script step “Insert from URL”.
Insert from URL [ Select ; No Dialog ; TABLE::postResult ; "https://maps.googleapis.com/maps/api/directions/json?...&key=[Your API Key]" ; Do not automatically encode URL ]
This means that it is compatible with both Desktop and iOS clients. In order to get multiple addresses sorted in the fastest route, you will need to set the flag “optimize:true”.
By setting the optimize flag, you are now required to enter the location of origin and destination, along with the waypoints you wish to visit in between. Details for how to set up the url request can be found on the Google Maps Directions Documentation.
Once a successful request has been made, a JSON-encoded response will be returned. You will then be able to use a plugin, a web viewer, or any JSON parser that you prefer to pull out the data that you need. Remember, if you need your solution to be mobile compatible, you can’t use a plugin unless you use Perform Script on Server. The Google Directions API returns complete directions with the response, so you can get as much or as little as you want out of it. By setting the optimize flag to true, the response will also include the order in which you should visit the provided waypoint locations.
... "summary" : "I-465 W", "warnings" : , "waypoint_order" : [ 1, 2, 3, 4, 5, 6, 0, 7 ] ...
In the example above, the waypoint order is what you will need to reference to order your locations. Starting with 0, you will want to rearrange your locations to so that they go from increasing order. The first waypoint put into the request will need to be the second waypoint visited. You will need to go through each location in the same order you passed to the API. Then, set each record with the number provided. When you sort the records by the corresponding waypoint, you will have the optimized route. Now, when you map the locations in this order, you will have the best route possible.
Save time and money optimizing your drive. Google has yet another API that us FileMaker users can easily integrate with and use. Feel free to contact us if you need further assistance or to discuss making your routes as optimized as possible with any other route optimizing APIs.
Download FileMaker Google Route Optimization Database
Please complete the form below to download your FREE FileMaker database file.
Did you know we are an authorized reseller for FileMaker Licensing?
Contact us to discuss upgrading your FileMaker software.