Blog
All Blog Posts | Next Post | Previous PostFreebie Friday: Google Maps API version
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.
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
This blog post has received 1 comment.
All Blog Posts | Next Post | Previous Post
Thorsten Hindermann