Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Example of using JavaScript for Google maps in the Delphi XE6

the future of starts demands massive productivity

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:

[crayon-67404905e5836396759943/]

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

[crayon-67404905e5842571951109/]

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

After it we add two const

[crayon-67404905e5846768276321/]

And two event handlers for button

[crayon-67404905e5848073136799/]

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

Exit mobile version