OverlayViewClick

I'm having a problem with OverlayViewClick event.

I can't reach the datastring of neither the marker nor the overlayview.

This is my code.

procedure TF_Miri_Abholung.AbhAdrMapOverlayViewClick(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
var
q : String;
lMarker : TTMSFNCGoogleMapsMarker;
lOverlay : TTMSFNCGoogleMapsOverlayView;
begin
q:=AEventData.Marker.DataString;

// lMarker:=AEventData.Marker as TTMSFNCGoogleMapsMarker;
// q:=lMarker.DataString;

// lOverlay:=lMarker.OverlayView as TTMSFNCGoogleMapsOverlayView;
// q:=lOverlay.DataString;
TDialogService.PreferredMode:=TDialogService.TPreferredMode.Platform;
TDialogService.MessageDialog('Zum Ort navigieren?', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], TMsgDlgBtn.mbYes,0,
procedure(const AResult: TModalResult)
begin
case AResult of
mrYes: begin
DM_Main.OpenNavigation(q, lMarker.Latitude, lMarker.Longitude);
end;
end;
end
);
end;

I'm getting an access violation at either "q:=AEventData.Marker.DataString;" or "q:=lMarker.DataString;" or
"lOverlay:=lMarker.OverlayView as TTMSFNCGoogleMapsOverlayView;"
I understand the violation on the last one, but not the other two.

Am I the problem or Taylor Swift?

Please note that AEventData of the OnOverlayViewClick event does not provide direct access to the Marker object associated with the clicked OverlayView.
However you can find the Marker by using the AEventData.ID value which contains the ID of the clicked OverlayView.

Example:

procedure TForm1.TMSFNCGoogleMaps1OverlayViewClick(Sender: TObject;
  AEventData: TTMSFNCMapsEventData);
var
  I: Integer;
begin
  for I := 0 to TMSFNCGoogleMaps1.Markers.Count - 1 do
  begin
     if AEventData.ID = TMSFNCGoogleMaps1.Markers[I].OverlayView.ID then
     begin
      ShowMessage(TMSFNCGoogleMaps1.Markers[I].DataString);
     end;
  end;
end;

That is a bit confusing and surprising as well.
Thank you for giving me a working solution!

I realize this might be confusing.
We'll investigate to improve this behavior in a future version.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.