1

I use TGMDirection to show routes between two markers I click on. It is the same idea like here, but in Delphi using GMLib 1.8: http://www.geocodezip.com/inventoresdegaragem_com_dbteste_indexB.html

First Direction It shows without any error. When I click again on another marker it pop up and Script error: Line: 539 Characters: 9 Error: Can not retrieve the value of the property close: object is null or undefined Code: 0 URL: about: blank

Do you have any Idea ? The code I use is:

procedure TForm1.GMMarker1DblClick(Sender: TObject; LatLng: TLatLng;
Index: Integer; LinkedComponent: TLinkedComponent);
begin
  if legcount = 0 then
  begin
    marker1index :=Index;
    legcount:=legcount+1;
  end
  else if legcount = 1 then 
  begin
    legcount:=0;
    marker2index :=Index;

    GMDirection1.DirectionsRequest.Origin.LatLng := GMMarker1.Items[marker1index].Position;
    GMDirection1.DirectionsRequest.Destination.LatLng := GMMarker1.Items[marker2index].Position;
    GMDirection1.Execute;

    if GMDirection1.DirectionsResult[routenr].Status = dsOK then 
    begin

      GMDirection1.Free;
    end;
    routenr:=routenr+1;
  end;
end;
jachguate
  • 16,976
  • 3
  • 57
  • 98
Vladds7
  • 81
  • 15

2 Answers2

2

I have found a bug into the InfoWindowCloseAll JavaScript function. You have two options to solve this problem.

1.- The easy: when you create the markers, put the Marker.InfoWindow.CloseOtherBeforeOpen property to False;

2.- The complex: you need to modify the HTML code and recompile resources and components. For do this, open the .\Resources\map.html with a text editor (like Notepad++) search the InfoWindowCloseAll function and modify it with this code:

function InfoWindowCloseAll() {
  for (i = 0; i < linkedCompList.length; i++) {
    if (linkedCompList[i] instanceof google.maps.InfoWindow) {
      linkedCompList[i].close();
      linkedCompList[i].GMLibIWIsOpen = false;
    }
    else {
      if (!(linkedCompList[i] instanceof google.maps.DirectionsRenderer)) {
        linkedCompList[i].GMLibInfoWin.close();
        linkedCompList[i].GMLibInfoWin.GMLibIWIsOpen = false;
      }
    }
  }
}

Save changes and compile resources with .\Resources\rc.cmd Now, recompile GMLib components and your application

Regards

cadetill
  • 1,552
  • 16
  • 24
  • Que bueno verte por aquí Cadetill. Yo había publicado una respuesta similar a la primera tuya, pero luego me di cuenta que no funcionaba. Un saludo y me alegra que se haya encontrado la fuente de este problema. – jachguate Nov 28 '12 at 05:17
0

To do this is very easy. You need 3 GMLib components (a TGMMap, a TGMMarker and a TGMDirection) and a TWebBrowser linked together. Set to false the GMDirection1.HiddeOthers property and into the OnClick GMMap event put this lines of code

procedure TForm1.GMMap1Click(Sender: TObject; LatLng: TLatLng; X, Y: Real);
begin
  GMMarker1.Add(LatLng.Lat, LatLng.Lng);
  if GMMarker1.Count mod 2 = 0 then
  begin
    GMDirection1.DirectionsRequest.Origin.LatLng.Assign(GMMarker1[GMMarker1.Count -   2].Position);
    GMDirection1.DirectionsRequest.Destination.LatLng.Assign(GMMarker1[GMMarker1.Count - 1].Position);
    GMDirection1.Execute;
  end;
end;

And that is all ;-)

Regards

cadetill
  • 1,552
  • 16
  • 24
  • Gracias Cadeetill! This code is very simple and beautiful. Unfortunately does not fit to my situation. I already have the markers on the map (read them from db) and I would like to make a direction when I double click on two distinct markers. For the first 2 markers works just fine, when I try to double click on the third marker I have this script error. – Vladds7 Nov 27 '12 at 17:21