TTMSFMXWebGMaps get Center position.


After I zoom, or move the TTMSFMXWebGMaps how can I get the new [latitude,longitude] center position of the map?

Also, how can I show a marker on the center of the map even when I'm moving it, scrolling or zooming?


The idea of the marker at center of the TTMSFMXWebGMaps is to have a reference in the entire screen.


You can use 

WebGMaps.MapPanTo(latitude, longitude);

You can add a marker at the latitude & longitude positions of your choice.

Thanks Bruno

But the NEW center values of latitudeand longitude AFTER move the map, zooming or resize where do I find them?

I mean the new position values of the center where is saved?

The center is the middle of the TBounds you can retrieve via calling WebGMaps.GetMapBounds and that are returned via the event OnBoundsRetrieved.


TBounds are giving in Latitude and Longitude values, or is measure in pixels?.

Because I need the center position given in coordinates.

It is longitude / latitude.

Bounds is related to TBounds

The next lines was extracted from FMX.types

TBounds = class(TPersistent)
    FRight: Single;
    FBottom: Single;
    FTop: Single;
    FLeft: Single;
    FOnChange: TNotifyEvent;
    FDefaultValue: TRectF;
    function GetRect: TRectF;
    procedure SetRect(const Value: TRectF);
    procedure SetBottom(const Value: Single);
    procedure SetLeft(const Value: Single);
    procedure SetRight(const Value: Single);
    procedure SetTop(const Value: Single);
    function IsBottomStored: Boolean;
    function IsLeftStored: Boolean;
    function IsRightStored: Boolean;
    function IsTopStored: Boolean;
    procedure ReadLeftInt(Reader: TReader);
    procedure ReadBottomInt(Reader: TReader);
    procedure ReadRightInt(Reader: TReader);
    procedure ReadTopInt(Reader: TReader);
    procedure ReadRectInt(Reader: TReader);
    procedure ReadRect(Reader: TReader);
    procedure DefineProperties(Filer: TFiler); override;
    procedure DoChange; virtual;
    constructor Create(const ADefaultValue: TRectF); virtual;
    procedure Assign(Source: TPersistent); override;
    function Equals(Obj: TObject): Boolean; override;
    function PaddingRect(const R: TRectF): TRectF;
    function MarginRect(const R: TRectF): TRectF;
    function Width: Single;
    function Height: Single;
    property Rect: TRectF read GetRect write SetRect;
    property DefaultValue: TRectF read FDefaultValue write FDefaultValue;
    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    function Empty: Boolean;
    function MarginEmpty: Boolean;
    function ToString: string; override;
    property Left: Single read FLeft write SetLeft stored IsLeftStored nodefault;
    property Top: Single read FTop write SetTop stored IsTopStored nodefault;
    property Right: Single read FRight write SetRight stored IsRightStored nodefault;
    property Bottom: Single read FBottom write SetBottom stored IsBottomStored nodefault;

So where are the longitude and latitude properties accordingly to you?

TBounds is defined in UWebGMapsCommonFunctions:

  TLocation = class(TPersistent)
    FLatitude: double;
    FLongitude: double;
    constructor Create;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
    property Latitude : double read FLatitude write FLatitude;
    property Longitude : double read FLongitude write FLongitude;

  TBounds = class(TPersistent)
    FNorthEast: TLocation;
    FSouthWest: TLocation;
    constructor Create;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
    property NorthEast : TLocation read FNorthEast write FNorthEast;
    property SouthWest : TLocation read FSouthWest write FSouthWest;


Once again, I'm looking just a simple two values as I wrote you before, one single value for latitude and one single value for longitude.

Seems you return cardinals values. When I add a marker or specify the DefaulLatitude and DefaultLongitude for start the Map your component require me just two floating point values correct?

Not NorthEast and SouthWest longitude and latitude values, seems you need to unify your own source code and make it pratical to us right?

I'm offering help on what's available and you can use right-now.

The center you ask for is the middle of NorthEast & SouthWest, so you can calculate that from these values.

I will assume a formula like:

latitude = (Bounds.NorthEast.Latitude + Bounds.SouthWest.Latitude) / 2;
longitude = (Bounds.NorthEast.Longitude + Bounds.SouthWest.Longitude) / 2;

Is the formula above correct?

Also when I call the GetMapBounds method how many times the BoundsRetrieved procedure is fire?

Because it's more than one time that BoundsRetrieved is called.
  1. Formula looks correct
    2) One call to GetMapBounds results in BoundsRetrieved triggered one time


Is there possible to remove all the links of the map?

I already adjust the properties in order to hide: map type, zoom level and so on.... But on the botton appears the google and the source info weblinks, so if for some reason I click on them my map will be forwarded to that weblink address.

The Google info/links at the right-bottom of the page is a restriction of Google and cannot be removed.


Is there possible to draw over the map some shape, or put some picture in that position, so that restriction be hidden?

Or maybe catch the event before redirect to the info/links?

I have not tried that. You could try to put a polygon rectangle in that position but I doubt Google wouldn't be smart enough to put their copyright always on top.

Let me try it, polygon must be draw on some canvas property?

This is some sample code to add a polygon:

  2.   pol: TPolygonItem;  
  3.   pt: TPath;  
  4.   pi: TPathItem;  
  6.   pt := TPath.Create();  
  8.   pi := pt.Add();  
  9.   pi.Latitude := 50;  
  10.   pi.Longitude := 2;  
  12.   pi := pt.Add();  
  13.   pi.Latitude := 50;  
  14.   pi.Longitude := 3;  
  16.   pi := pt.Add();  
  17.   pi.Latitude := 55;  
  18.   pi.Longitude := 2.5;  
  21.   pol := WebGMaps1.Polygons.Add(falsefalsefalse, pt, clRed, clYellow, 255, 255, 2, true, 255);  
  23.   WebGMaps1.CreateMapPolygon(pol.Polygon);