1

我使用 TGMDirection 来显示我点击的两个标记之间的路线。与这里的想法相同,但在 Delphi 中使用 GMLib 1.8: http ://www.geocodezip.com/inventoresdegaragem_com_dbteste_indexB.html

第一方向 它显示没有任何错误。当我再次单击另一个标记时,它会弹出并脚本错误:行:539 个字符:9 错误:无法检索属性关闭的值:对象为空或未定义代码:0 URL:关于:空白

你有什么主意吗 ?我使用的代码是:

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;
4

2 回答 2

2

我在 InfoWindowCloseAll JavaScript 函数中发现了一个错误。您有两种选择来解决这个问题。

1.- 简单:创建标记时,将 Marker.InfoWindow.CloseOtherBeforeOpen 属性设置为 False;

2.- 复杂:您需要修改 HTML 代码并重新编译资源和组件。为此,请使用文本编辑器(如 Notepad++)打开 .\Resources\map.html 搜索 InfoWindowCloseAll 函数并使用以下代码对其进行修改:

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;
      }
    }
  }
}

使用 .\Resources\rc.cmd 保存更改并编译资源 现在,重新编译 GMLib 组件和您的应用程序

问候

于 2012-11-27T22:43:14.453 回答
0

做到这一点非常容易。您需要 3 个 GMLib 组件(一个 TGMMap、一个 TGMMarker 和一个 TGMDirection)和一个链接在一起的 TWebBrowser。将 GMDirection1.HiddeOthers 属性设置为 false 并在 OnClick GMMap 事件中放入这行代码

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;

这就是全部;-)

问候

于 2012-11-27T15:16:00.450 回答