TTMSFMXWebGMaps get Center position.

Hello

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?


Thanks

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

Thanks

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.

Bruno


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)
  private
    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);
  protected
    procedure DefineProperties(Filer: TFiler); override;
    procedure DoChange; virtual;
  public
    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;
  published
    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;
  end;


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

TBounds is defined in UWebGMapsCommonFunctions:


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

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

Bruno



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

Bruno



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.



Alright

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:


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