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;
Please note that Rectangle bounds are not automatically updated after editing.
You can access the updated values through the AEventData.CustomData value.
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?
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}}"
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.
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;