【发布时间】:2013-05-05 22:41:13
【问题描述】:
有人可以给我一个简单的示例,我如何使用 GMLib 实现以下情况: 我有一些地址(街道、号码、城市),我想使用谷歌地图制作一条连接所有地址的路线。 我正在使用德尔福 XE2。 非常感谢!
【问题讨论】:
标签: delphi delphi-xe2 gmlib
有人可以给我一个简单的示例,我如何使用 GMLib 实现以下情况: 我有一些地址(街道、号码、城市),我想使用谷歌地图制作一条连接所有地址的路线。 我正在使用德尔福 XE2。 非常感谢!
【问题讨论】:
标签: delphi delphi-xe2 gmlib
您需要一个 TWebBrowser、一个 TGMMap 和一个 TGMDirection 并连接这些组件:
TGMDirection.Map -> TGMMap TGMMap.WebBrowser -> TWebBrowser
Active TGMMap (Active := true) 并在 AfterPageLoaded 事件上放置此代码:
procedure TMainFrm.GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
begin
if First then GMMap1.DoMap;
end;
现在,您只需要配置您的 TGMDirection 与 Origin 和 Destination 地址并调用 Execute 方法:
// minimum config
TGMDirection.DirectionsRequest.Origin.Address := 'Origin address';
TGMDirection.DirectionsRequest.Destination.Address := 'Destination address';
TGMDirection.Execute;
你需要知道所有对 Execute 方法的调用都会在 DirectionsResult 数组中创建一个新的 Item。该数组有 Count 个项目(基于 0)。您还需要知道每个结果可以返回(如果 Status = dsOK)1 个或多个结果存储到 Routes 数组中(也基于 0)。
TGMDirection.DirectionsResult -> array with all request
TGMDirection.DirectionsResult[X].Routes -> array with all results of a request if Status = dsOK
问候
【讨论】: