qGold
qGold

Reputation: 341

Draw a Line between two coordinates in a TMapView (Delphi FMX)

I have a TMapView on my Form. The TMapView works fine so far but I want to add the possibility to draw a Line between two coordinates on the TMapView. How can I do that?

I tried the following which does not work in any way:

var
A,B: TMapCoordinate;
AB: TMapPolylineDescriptor;
begin
A.Latitude:=51.88;
A.Longitude:=10.56;
B.Latitude:=51.9;
B.Longitude:=10.7;
//MapView1.Canvas.DrawLine(A,B,50); //doesnt work
// AB.Points:=[A,B]; //doesnt work too
AB.StrokeWidth:=50;
//MapView1.AddPolyline(AB); //doesnt work too
end;

I guess the canvas thing wont work as I want as I think it just connects points on the TMapView as a Bitmap and not on the map itself. Please suggest me how I can draw a Line between two coordinates on the map (if that is possible)

I use Delphi 10.3.3 Community Edition and try to compile it on my android 10 phone.

I found this SO Link where the Polyline is used in Objective-C for MapKit on iPhone. I guess I have to do the same thing in delphi, but I have no idea how to do this.. but I saw Polyline draws a maps route between two points. Thats good to know too, but I just want my Line drawn and no maps route suggestion from Google.

if I use this code:

  if MapView1.Canvas.BeginScene then
  begin
    Canvas.Fill.Color := $FF111111 + random($FFFFFF);
    Canvas.Fill.Kind := TBrushKind.Solid;
    Canvas.FillRect(RectF(random(300), random(300), random(300), random(300)),
    0,
    0, [], 1);
    Canvas.EndScene;
  end;

it works and draws a colored Rectangle somwhere in some color, but is disappears immediately after showing up.. maybe thats why my Lines arent visible too. Maybe they're painted but overpainted immediately. I Dont know much about canvas of my TMapView or Canvas in general, but after painting the "square" it dissappears and I guess those Lines are just disappearing too. Can I somehow make those selfpainted canvas changes permanent until I overpaint them by myself?

Upvotes: 1

Views: 866

Answers (1)

Moskwa
Moskwa

Reputation: 121

try to use like that

var
A,B: TMapCoordinate;
AB: TMapPolylineDescriptor;
begin
  A := TMapCoordinate.Create(51.88,10.56);
  B := TMapCoordinate.Create(51.9,10.7);

  AB := TMapPolylineDescriptor.Create([A,B]);
  AB.StrokeWidth:=5;
  MapView1.AddPolyline(AB);
end;

Upvotes: 2

Related Questions