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;
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
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
来源:https://stackoverflow.com/questions/13583783/tgmdirection-script-error