views:

284

answers:

4

Hi,

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

+3  A: 

@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.

RRUZ
Just curious. I see you always include "@..." in your answers. Is there a reason why you do that? It would seem obvious to me that your answer is directed at the person who asked the question?
Marjan Venema
@Marjan. In case of multiple comments (which may or may not stay in chronological order), it helps in addressing a specific user. It's a de facto standard...
François
@François: Yes in comments. But RRUZ is doing it in answers as well, which made me curious as to whether (s)he may have a reason for doing it there as well.
Marjan Venema
@François - good point. +1 for proper use of "de facto". Hopefully this comment will be shuffled out of order, to further demonstrate the point.
Chris Thornton
@Marjan A by-product of too much twitter? <-(Oh no I did it too!)
codeelegance
A: 

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/

zerolith
A: 

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...

Wouter van Nifterick