Google Rectangle - PolyElementEditEnd

After adjusting a rectangle object on the screen, I'm trying to get the boundary Lat/Lons - but the NorthEast and SouthWest values are the same.

Here is my code. I'm not sure what else to try.

procedure TFFuncs_GoogleFNC.FNCGoogleMapsPolyElementEditEnd(Sender: TObject;
AEventData: TTMSFNCMapsEventData);
var b: TTMSFNCMapsBoundsRec;
MyRec:TTMSFNCGoogleMapsRectangle;
begin
if Assigned(AEventData.PolyElement) then
begin
if (AEventData.PolyElement is TTMSFNCGoogleMapsRectangle) then
begin
if ffuncs.FormExists('FGeoFence') then
begin
MyRec:=(AEventData.PolyElement as TTMSFNCGoogleMapsRectangle);
b:=MyRec.Bounds.ToRec;

   FGeoFence.YCoord:=b.NorthEast.Latitude;
   FGeoFence.XCoord:=b.NorthEast.Longitude;
   FGeoFence.YCoord2:=b.Southwest.Latitude;
   FGeoFence.XCoord2:=b.Southwest.Longitude;

   FGeoFence.UpdateGeoLabels;                        // Update the Labels
   end;
 end;

end;
end;

Hi,

Please note that Rectangle bounds are not automatically updated after editing.
You can access the updated values through the AEventData.CustomData value.

This is explained in the online documentation:

That was the very first thing I tried - was the documentation. Except, ".Bounds.JSON'" is not declared. Which is why I was trying a different route.

See the compile issue here?

image

image

I can see the coordinates in the AEventData.CustomData, but bringing that into a JSON object, I cannot parse it. Seems like some odd JSON of some sort.

Is there a different way of accessing the coordinates of the rectangle?

Here is what the JSON looks like:
"{"$type":"TTMSFNCMapsBounds","NorthEast":{"$type":"TTMSFNCMapsCoordinate","Latitude":38.82094118,"Longitude":-121.25695673980488},"SouthWest":{"$type":"TTMSFNCMapsCoordinate","Latitude":38.80462267562648,"Longitude":-121.28442256}}"

Also, I looked at another ticket on here and saw you created a TCoordinateList type and tried that. It just won't resolve .JSON

For the time being, I just did string manipulation of the CustomData.

.JSON is a class helper that is added when adding the unit FMX.TMSFNCTypes.pas

I added that to the Uses clause in my unit and it still shows .Bounds.JSON as not a member.

It compiles just fine here.

unit Unit20;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.TMSFNCTypes, FMX.TMSFNCUtils, FMX.TMSFNCGraphics, FMX.TMSFNCGraphicsTypes,
  FMX.TMSFNCCustomControl, FMX.TMSFNCWebBrowser, FMX.TMSFNCMaps,
  FMX.TMSFNCGoogleMaps;

type
  TForm20 = class(TForm)
    TMSFNCGoogleMaps1: TTMSFNCGoogleMaps;
    procedure TMSFNCGoogleMaps1PolyElementEditEnd(Sender: TObject;
      AEventData: TTMSFNCMapsEventData);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form20: TForm20;

implementation

{$R *.fmx}

procedure TForm20.TMSFNCGoogleMaps1PolyElementEditEnd(Sender: TObject;
  AEventData: TTMSFNCMapsEventData);
begin
  (AEventData.PolyElement as TTMSFNCGoogleMapsRectangle).Bounds.JSON := AEventData.CustomData;
end;

end.

Please check and make sure the correct units are added.

Now that I see your uses clause, here is the difference.

One unit includes:
VCL.TMSFNCMaps,VCL.TMSFNCGoogleMaps,
VCL.TMSFNCCustomComponent, VCL.TMSFNCRouteCalculator,
VCL.TMSFNCMaps.GoogleMaps,VCL.TMSFNCMapsCommonTypes,FMX.TMSFNCTypes;

The other unit that has the GoogleMaps itself, has these units:
VCL.TMSFNCTypes,
VCL.TMSFNCUtils, VCL.TMSFNCGraphics, VCL.TMSFNCGraphicsTypes,
VCL.TMSFNCCustomControl, VCL.TMSFNCWebBrowser, VCL.TMSFNCMaps,
VCL.TMSFNCGoogleMaps,VCL.TMSFNCMaps.GoogleMaps;

Because I already have a reference to VCL.TMSFMCMapsCommonTypes (needed for TTMSFNCMapsCoordinateRec and TTMSFNCMapsBoundsRec) because the FMX are incompatible, the VCL version does not include the ".JSON" property. That's the issue.

I tried changing the other VCL references to FMX, but that caused more problems and for some units, the compiler put back the VCL version.

Each framework has it's own units.

For VCL, you need to add VCL.TMSFNCTypes.

In VCL, or FMX, both are working

unit Unit22;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VCL.TMSFNCTypes, VCL.TMSFNCUtils,
  VCL.TMSFNCGraphics, VCL.TMSFNCGraphicsTypes, Vcl.StdCtrls,
  VCL.TMSFNCCustomControl, VCL.TMSFNCWebBrowser, VCL.TMSFNCMaps,
  VCL.TMSFNCGoogleMaps;

type
  TForm22 = class(TForm)
    TMSFNCGoogleMaps1: TTMSFNCGoogleMaps;
    Button1: TButton;
    procedure TMSFNCGoogleMaps1PolyElementEditEnd(Sender: TObject;
      AEventData: TTMSFNCMapsEventData);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form22: TForm22;

implementation

{$R *.dfm}

procedure TForm22.TMSFNCGoogleMaps1PolyElementEditEnd(Sender: TObject;
  AEventData: TTMSFNCMapsEventData);
begin
  (AEventData.PolyElement as TTMSFNCGoogleMapsRectangle).Bounds.JSON := AEventData.CustomData;
end;

end.

Seems like that fixed it. Here is the final for others if they run into this.

uses (top of the unit)
  VCL.TMSFNCTypes, VCL.TMSFNCUtils,VCL.TMSFNCMapsCommonTypes,
  VCL.TMSFNCGraphics, VCL.TMSFNCGraphicsTypes,VCL.TMSFNCMaps.GoogleMaps,
  VCL.TMSFNCCustomControl, VCL.TMSFNCWebBrowser, VCL.TMSFNCMaps,
  VCL.TMSFNCGoogleMaps, VCL.TMSFNCCustomComponent, VCL.TMSFNCRouteCalculator;
.
.
.

procedure TFFuncs_GoogleFNC.FNCGoogleMapsPolyElementEditEnd(Sender: TObject;
  AEventData: TTMSFNCMapsEventData);
var MyRec:TTMSFNCGoogleMapsRectangle;
begin
 if Assigned(AEventData.PolyElement) then
   begin
   if (AEventData.PolyElement is TTMSFNCGoogleMapsRectangle) then
     begin
     if ffuncs.FormExists('FGeoFence') then
       begin
       MyRec:=(AEventData.PolyElement as                 // Assign Rectangle
               TTMSFNCGoogleMapsRectangle);
       MyRec.Bounds.JSON:=AEventData.CustomData;         // Push Coordinates to it

       FGeoFence.YCoord:=                                // Post to FGeoFence
         MyRec.Bounds.NorthEast.Latitude;
       FGeoFence.XCoord:=
         MyRec.Bounds.NorthEast.Longitude;
       FGeoFence.YCoord2:=
         MyRec.Bounds.Southwest.Latitude;
       FGeoFence.XCoord2:=
         MyRec.Bounds.Southwest.Longitude;
       end;
     end;
   end;
end;