2
votes

In this project my aim is to create a software via GoogleMaps in Delphi 2009, it will be like this one but in different way. In this project the user can add a point on the map and in every point beside the icon I will add some information and these information should be relate with the icon, so if the user want to click on one of them the information will open automatically. My problem is I can create the information but when I close it I can not open it again. How can I manage this problem my code as below, Thanks a lot.

  procedure TfrmMain.btnAddMarkerClick(Sender: TObject);
var
   Doc2: IHTMLDocument2;
   Win2: IHTMLWindow2;
   latlng: String;
   information: String;
begin
   Doc2 := WebBrowser1.Document as IHTMLDocument2;
   Win2 := Doc2.parentWindow;
   information:='its a example';
    latlng := '"' + leLat.Text + '", "' + leLng.Text + '"';

  Win2.execScript('map.addOverlay(new GMarker(new GLatLng(' + latlng + ')) );', 'JavaScript');
  Win2.execScript('map.openInfoWindow(new GLatLng(' + latlng + '),document.createTextNode("'+information +'"));','JavaScript');

   end;

The Design as below: alt text http://img829.imageshack.us/img829/8474/adszdi.png

3
What do you mean by "I can create the information but when I close it I can not open it again"? Could you elaborate a little?Mason Wheeler
The project you've described sounds like Google's own "My Maps" feature. Are you sure you need to do this project at all?Rob Kennedy

3 Answers

3
votes

@asilloo, The Google maps API does not save your markers, this information is valid only in the current session of your browser, if do you need persist (store) the markers you must do it yourself manually, you can use a database or an xml file. i recomend do you use the KML format for this task.

0
votes

i created solution with the Google Maps Flex (Flash) API by embedding the Flash OCX Control in Delphi. For me its much faster and i'm able to pass/retrieve complex parameters.

maybe you give it a try: http://www.delphiflash.com/

0
votes

The problem in your code is that you don't save any reference to the infowindow. The infowindow is shown, and indeed, when you close it, it's gone.

If I understand what you want correctly, you should add an eventhandler to the markers that you create.

You should do it like this:

  • Create a marker object
  • Attach an onclick event handler. In that event handler you open the info window
  • Add the marker to the map

Code:

Win2.execScript('var marker=new GMarker(new GLatLng(' + latlng + '));', 'JavaScript');
Win2.execScript('GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml("'+information +'"); });', 'JavaScript');
Win2.execScript('map.addOverlay(marker);', 'JavaScript');

(sorry if there are some syntax errors here.. I've edited it in this crappy textbox on stackoverflow)

Let me know if it works...