RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
Delphi

Example of using JavaScript for Google maps in the Delphi XE6

Author: Nikolay M4446

One of the innovations in XE6, it’s a method EvaluateJavaScript in the component TWebBrowser. This method allowing execute JavaScript on the loaded page and add interactivity to our applications.

On the site developers.google.com contains many examples of embedding maps on the page. I chose the example for paving the route from point A to point B. And as an example of execution JavaScript, I define two buttons for showing predefined paths from “Chicago” to “Winona” and from “St Louis” to “Gallup”.

Make a new mobile project and drop on the main form TWebBrowser, TPanel and place two TButton on the TPanel.

For convenience, I create just one more unit uJavaScripts.pas. This unit will contain the HTML code of pages and scripts themselves. Most dreary – copy and past example of code and place it as a constant in our unit. I’ve got to do something like this:

Entire code example is taken from the site Google.
We need load it to the browser. For this event, write this code in the FormCreate

We can run it. It looks on the iPhone 5 as on the picture

After it we add two const

And two event handlers for button

Thats it. Now we can choise peath using HTML conntrols or use predefined paths using buttons.

On the iPhone and Kindle Fire HD its look like this


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Learn More About Upgrading

Deep Dive Webinar: Boost C++Builder Compile Speed with TwineCompile
Related posts
DelphiRAD Studio

Learn To Add Custom Text Rendering And Formatting Capabilities To Your Delphi FMX Controls Quickly

CodeDelphiRAD Studio

Quickly Learn How To Optimize Your Delphi Apps With ProDelphi In This CodeRage Replay

DelphiShowcase

Easy-to-use Orbit Simulator Built In Delphi FireMonkey For Learning Gravitational Physics

DelphiShowcase

Powerful Cross Platform Multitrack Music Recording Software Built In Delphi FireMonkey

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES