Mapping application

We have a marketable product written in Delphi 6 that provides information on various establishments in the UK.  We want to be able to display the set of establishments from a search in a Google style map with flags marking the location of each establishment. with a popup box for each flag that could contain a link either to an external web page or to an internal function within the application that could say display detailed information about the establishment.

I have obtained a javascript using Google Maps which does what I want it to do and can run it in an external web browser.  However, I cannot seem to run it within a Delphi TWebBrowser, which is probably what I would need to do.

Also are there any licencing implications using Google Maps in a commercial application?  If so, what other packages are there that would integrate into Delphi 6.
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"  
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <title>Google Maps JavaScript API Example</title> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAA.....&sensor=false" 
            type="text/javascript"></script> 
    <script type="text/javascript"> 
 
    function initialize() { 
      if (GBrowserIsCompatible()) { 

        function createMarker(point,html) {
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
          });
          return marker;
        }

        var map = new GMap2(document.getElementById("map_canvas")); 

        map.setCenter(new GLatLng(51.54, -0.136), 12); 
        map.setUIToDefault(); 

// Add 10 markers to the map at random locations 
        var bounds = map.getBounds(); 
        var southWest = bounds.getSouthWest(); 
        var northEast = bounds.getNorthEast(); 
        var lngSpan = northEast.lng() - southWest.lng(); 
        var latSpan = northEast.lat() - southWest.lat(); 
        for (var i = 0; i < 10; i++) 
	{ 
          var point = new GLatLng(southWest.lat() + latSpan * Math.random(), 
                southWest.lng() + lngSpan * Math.random()); 
          var marker = createMarker(point,'Some stuff to display in the Info Window')
          map.addOverlay(marker); 
        }        

      } 

    } 

 
    </script> 
  </head> 
  <body onload="initialize()" onunload="GUnload()"> 
    <div id="map_canvas" style="width:975px; height: 620px"></div> 
  </body> 
</html>

Open in new window

rogerfg7Asked:
Who is Participating?
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
I found that strange the need to use a stringlist, and playing a bit it's not needed. I use ANSIString also to avoid problems with Delphi 2009, 2010 unicode strings

WBLoadHTML ( WebBrowser1,
  '<a href="http://delphi.about.com">GOTO</a><b>About Delphi Programming</b>' );
procedure WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: ANSIString) ;
var
 ms: TMemoryStream;
begin
 WebBrowser.Navigate('about:blank') ;
 while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
  Application.ProcessMessages;
 if Assigned(WebBrowser.Document) then
  begin
   ms := TMemoryStream.Create;
   try
    ms.Write(HTMLCode[1], Length(HTMLCode));
    ms.Position:=0;
    (WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms)) ;
   finally
     ms.Free;
   end;
  end;
end;

Open in new window

0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
I suspect that maybe GBrowserIsCompatible will return false with a TWebBrowser.
Perhaps you can try to not call it and create your markers directly ?
0
 
rogerfg7Author Commented:
|I have got it to run by writing the code to a file then calling the WebBrowser Navigate method with the file name.  It does run but slowly (20 seconds as opposed to 5 seconds in IE 8).  Ideally I would like to get the same result but without writing to a file and then loading.  Is there no methods associated with TWebBrowser that would would allow the javascript code to be run directly from Delphi code and the markers to be added on the fly.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
8080_DiverCommented:
You don't mention what your database is; however, SQL Server 2008 (Express) has some mapping functionalities.
0
 
rogerfg7Author Commented:
We are retrieving the data from Paradox tables, but all the info is stored in objects.  I have the code working correctly now after translating GIS conversion routines into Delphi.  However, I still have to write the javascript to a file on disk and then call WebBrowser.Navigate2 to load the file.  It would be nice to be able to pass the javascript directly to the WebBrowser.
0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
0
 
rogerfg7Author Commented:
Thanks.  Works a treat.

I did find a wrapper for TWebBrowser, which allows more Delphi like code

http://www.delphidabbler.com/articles?article=14&part=1#stage1-docload

But yours works for what I need.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.