Delphi Google Map API:如何为每个Waypoint添加特定图标?

时间:2014-08-28 08:00:08

标签: google-maps delphi icons gmlib

我使用GMLib 1.1.0.00 - 谷歌地图库和我的Delphi 7。

我需要在谷歌地图上显示一组点,用道路来建立行程。

使用此代码可以正常工作但是,我需要在每个航路点上放置一个特定的图标。 但设置图标的唯一方法是WayPointList.icon上的属性......

procedure TfrmMap.FillMarker;
var
i                      : Integer;
sAdr                   : string;
gmllLoc                : TLatLng;
gmMk                   : TMarker;
Count: Integer;
sTitle: string;
const
MAX_REQUEST = 100;
begin
  gmMarker.Clear;
  Count := Min(MAX_REQUEST, recCustomLocS.LocCount);
  for i := 0 to Count - 1 do
  begin

    if(i = 4) then
    begin
      Break;
    end;

    try
      // Build Adress
      sAdr := recCustomLocS.arGMCustomersLocation[i].Country;
      if sAdr <> '' then
      begin
        sAdr := 'Belgium';
      end;
      sAdr := sAdr + ' ' + recCustomLocS.arGMCustomersLocation[i].PostCode + ' '
        + recCustomLocS.arGMCustomersLocation[i].City + ' '
        + recCustomLocS.arGMCustomersLocation[i].Adress;

      // Geolocalize address
      gmGeoCde.Geocode(sAdr);

  case gmGeoCde.GeoStatus of
    gsOK:
      begin
        if gmGeoCde.Count > 0 then
        begin
          gmllLoc := gmGeoCde[0].Geometry.Location;

          // Set Title
          sTitle := recCustomLocS.arGMCustomersLocation[i].CustName;
          if sTitle = '' then
            sTitle := IntToStr(recCustomLocS.arGMCustomersLocation[i].RepairNo);

          // Add direction to map
          if( i = 0) then
          begin
            GmDirection1.DirectionsRequest.Origin.Address :=  sAdr;
          end
          else
          begin
            if(i = 3) then
            begin
              GmDirection1.DirectionsRequest.Destination.Address := sAdr;
            end
            else
            begin
              GmDirection1.DirectionsRequest.WaypointsList.Add.Location.Address := sAdr;
              GmDirection1.DirectionsRequest.WaypointsList.Items[0].DisplayName := 'TEST NICO';
              GmDirection1.DirectionsRequest.WaypointsList.Items[0].StopOver := true;
              GmDirection1.DirectionsRender.MarkerOptions.Icon := sIconGreen;
            end;
          end;
        end;
      end;
  end;
except
  on E: Exception do
    ShowMessage(e.Message);
end;
end;
GmDirection1.Execute;
end;

我尝试使用GMMarkers的另一种解决方案,但是通过这个程序,我不知道如何在每个点之间追踪道路?

// Add Marker to map
          gmMk := gmMarker.Add(gmllLoc.Lat,gmllLoc.Lng,sTitle);
          gmMk.MarkerType := mtStandard;

          case recCustomLocS.arGMCustomersLocation[i].color of
            clBlue: gmMk.Icon := sIconBlue;
            clRed: gmMk.Icon := sIconRed;
          else
            gmMk.Icon := sIconGreen;
          end;

          gmMk.OpenCloseInfoWin;
          //TInfoWindow(gmMk.InfoWindow).AutoOpen := True;
          gmMk.InfoWindow.CloseOtherBeforeOpen := True;
          gmMk.ShowInfoWinMouseOver := True;
          //gmMk.InfoWindow.HTMLContent := '<div style=''width:250px;margin:0 0 20px 20px;max-height:90px;''>'
          gmMk.InfoWindow.HTMLContent := '<div style=''width:200px;max-height:90px;''>'
            + ' <b>' + IntToStr(recCustomLocS.arGMCustomersLocation[i].RepairNo) + '</b>'
            + StringOfChar(' ',30 - Length(recCustomLocS.arGMCustomersLocation[i].CustName))
            + '<i> ' + recCustomLocS.arGMCustomersLocation[i].CustName + '</i>'
            + '<br>' + recCustomLocS.arGMCustomersLocation[i].Adress + '<br>'
            + recCustomLocS.arGMCustomersLocation[i].PostCode + ' ' + recCustomLocS.arGMCustomersLocation[i].City
            + '</div>';
            }
        end;

非常感谢你的帮助;)

0 个答案:

没有答案