Blog

All Blog Posts  |  Next Post  |  Previous Post

Freebie Friday: Google Maps API version

Bookmarks: 

Friday, July 7, 2023

It's Friday, and it's time for a freebie. This time around, this freebie is based on a customer question we came across recently. In TMS FNC Maps, we have a separate Google Maps based component. Each time Google pushes an update, the version number is increased and for us developers, needing to change the version number to get access to the latest API changes / features would be a hassle and require a release of our software everytime this happens.

TMS Software Delphi  Components

Google Maps sample image

Weekly

Luckily, Google implemented a system that allows users to configure the API to automatically pick up the latest stable version. The recommended API version is weekly. This is the most current and up-to-date version and contains the latest bug fixes and performance improvements. If, for some reason, the application/component is behaving unexpected, it's possible to temporarily change the versioning to beta, quarterly or to a specific version. This can be done with

TMSFNCGoogleMaps1.Options.Version

More information about versioning can be found here: https://developers.google.com/maps/documentation/javascript/versions

Version number

Even when the component is managing the versioning automatically, it might be of interest to check which version number the API is actually targeting. Last week, we had a question from a customer related to retrieving the version number.

Can the current API version be obtained using the ExecuteJavaScript routine? I cannot find any examples on the web and am unaware of a way to obtain them through the Map object. For example, the FNCGoogleMaps.Options.Version is set to 'weekly', but there isn't a way to know if the map uses Google API version 3.52, 3.53, 3.53.1, etc. It would be nice to know which version is getting loaded to decide if we want to execute new API features, but I don't know which version is loaded. Any help would be greatly appreciated.

Immediately, we jumped on this question and came up with a nice solution.

procedure TForm1.TMSFNCMaps1MapInitialized(Sender: TObject);
var
 t: ITask;
begin
 t := TTask.Create(
 procedure
 begin
   TThread.Synchronize(TThread.Current,
   procedure
   begin
     TTMSFNCUtils.Log(TMSFNCMaps1.ExecuteJavaScriptSync('google.maps.version;'));
   end);
 end
 );
 t.Start;
end;

To solve this, we needed to implement the OnMapInitialized event, to make sure Google Maps API is properly loaded and the map is initialized. Then, start a thread because in Windows, Edge Chromium execute JavaScript calls cannot be executed from events, as they are called from within the browser thread and this would cause a lockup. Then, executing a synchronous JavaScript call retrieving the current Google Maps version the API is running on.

Feedback

From time to time, we come across questions that eventually make our components better. This particular question ended up with a code snippet, not only helping the customer, but also helping others with the same question. When something is non-trivial like this, we tend to integrate this as a feature or improvement in the component itself. This is why feedback, questions like this only make our components better and eventually your application. Don't hesitate to provide us feedback through our typical communication channels.



Pieter Scheldeman


Bookmarks: 

This blog post has received 1 comment.


1. Friday, July 7, 2023 at 5:36:40 PM

Very cool new feature. I am happy to obtain the TMS FNC components. And your support to make these components better and better over the time. Thank you all for this effort!

Thorsten Hindermann




Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post