简体   繁体   中英

GMLib Simple directions sample

someone could give me a simple sample how could i implement the follow situation using GMLib: I have some address(street, number, city) ei would like to make a route using the google maps connecting all of them. I am using Delphi XE2. Thanks very much!

You need a TWebBrowser, a TGMMap and a TGMDirection and connect the components so:

TGMDirection.Map -> TGMMap TGMMap.WebBrowser -> TWebBrowser

Active TGMMap (Active := true) and on AfterPageLoaded event put this code:

procedure TMainFrm.GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
begin
  if First then GMMap1.DoMap;
end;

Now, you only need to configure your TGMDirection with Origin and Destination address and call Execute method:

// minimum config
TGMDirection.DirectionsRequest.Origin.Address := 'Origin address';
TGMDirection.DirectionsRequest.Destination.Address := 'Destination address';
TGMDirection.Execute;

You need to know that all call to Execute method create a new Item into DirectionsResult array. This array have Count items (0 based). Also you need to know that each result can return (if Status = dsOK) 1 or more results stored into Routes array (0 based too).

TGMDirection.DirectionsResult -> array with all request
TGMDirection.DirectionsResult[X].Routes -> array with all results of a request if Status = dsOK

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM