The
other day I blogged about mashing up
Google Maps and VCL in a Delphi Win32 application with support for bi-directional VCL-> JavaScript and JavaScript-> VCL allowing for rich interaction with the map. The first part of this "conversation" is actually very easy to accomplish. Here is what you need to do if you want to give it a try. I'll talk about this from the Delphi perspective though the same logic will work from C# or any other language that can host the
Microsoft WebBrowser control.
- Start a new VCL application
- Drop a TWebBrowser control
- Create a Form1.OnCreate event handler
- Add the following line of code:
WebBrowser1.Navigate(
'http://www.stevetrefethen.com/files/googlemap.htm');
- Add a TButton to the form and an OnClick event handler and add the following code:
procedure TForm1.Button1Click(Sender: TObject);
var
Doc2: IHTMLDocument2;
begin
with WebBrowser1.Document as IHTMLDocument2 do
with parentWindow do
execScript('createMapMarker("31.05173494",
"-122.03160858", "test")', 'JavaScript');
end;
This will create a new marker on the map in Scotts Valley, CA. In fact, you can execute any method of the Google Map object by replacing the first parameter in execScript (above) with something like this:
map.panTo(new GLatLng(37.05173492, -122.031608568));
Hopefully, you can see the possibilities this creates. To get it working on your own domain you'll need to do the following:
- Get yourself GMail account if you don't already have one
- Get a Google Maps API key you'll need a domain where you can upload files to
- Right click and save this file to disk
- Edit the file you just download and change the API to use your key (mine won't work on your domain)
- Change the .Navigate call to use your URL
That's it, you can now interact with Google maps from a Windows client application (VCL in this case). As you can see mashups aren't strictly the domain of web only applications. In a subsequent post I'll talk about how to interact with the hosting application from the JavaScript on the page for true two way interaction.
[UPDATE: April 2, 2008] Related posts:
Google|
Maps|
Win32|
WebBrowser|
Mashup
a18e0a01-0df8-454b-a420-3546c9d0868c|0|.0
Tags: Programming