Table of Contents

TMS FNC Static Map — Guides

Service configuration

Set Service to choose the static map provider: smGoogle, smHere, smMapBox, smAzure, smTomTom, or smBing. Set APIKey to a key issued by that provider — each backend builds its own request URL, so a key is only valid for the service it was issued for.

Requesting a map image

GetStaticMap is a function that returns the provider's image URL; it does not perform the download and there is no completion event. Two overloads are available: one taking a TTMSFNCMapsCoordinateRec center (build one with CreateCoordinate), and one taking an address string. Width, height, zoom, marker visibility, and TTMSFNCStaticMapType are all optional parameters with defaults (640, 480, zoom 10, marker on, mtDefault).

Hand the returned URL to whatever loads remote images in your application.

HERE service

The HERE backend targets the HERE Maps Image API v3 (image.maps.hereapi.com/mia/v3), so the key must be provisioned for that service — a key limited to an earlier Map Image API version is refused. Each TTMSFNCStaticMapType maps onto a v3 style name (satellite.day, explore.satellite.day, topo.day, lite.day, explore.night); mtDefault sends no style and lets the service choose.

Note

The HERE backend resolves the image from a coordinate. The address-string overload falls back to the default coordinate for this service, so pass a coordinate — geocode the address first if you only have text.

uses
  FMX.TMSFNCStaticMap, FMX.TMSFNCMapsCommonTypes;

procedure TForm1.ShowHereMapButtonClick(Sender: TObject);
var
  LURL: string;
begin
  TMSFNCStaticMap1.Service := smHere;

  // The HERE backend targets the HERE Maps Image API v3
  // (image.maps.hereapi.com/mia/v3), so the key must be issued for that
  // service; a key limited to an earlier Map Image API version is rejected.
  TMSFNCStaticMap1.APIKey := MyHereApiKey;

  // GetStaticMap returns the image URL directly - it is a function, not an
  // asynchronous request, so there is no completion event to wait for.
  LURL := TMSFNCStaticMap1.GetStaticMap(
    CreateCoordinate(51.5074, -0.1278),  { center: London }
    640, 480,                            { width and height in pixels }
    12,                                  { zoom level }
    True,                                { draw a marker on the center }
    mtDefault);

  Memo1.Lines.Add(LURL);
end;

procedure TForm1.ShowHereStylesButtonClick(Sender: TObject);
var
  LCenter: TTMSFNCMapsCoordinateRec;
begin
  TMSFNCStaticMap1.Service := smHere;
  TMSFNCStaticMap1.APIKey := MyHereApiKey;

  LCenter := CreateCoordinate(48.8566, 2.3522);

  // Each map type maps onto a HERE v3 style name. mtDefault sends no style at
  // all and lets the service pick its own default.
  Memo1.Lines.Add(TMSFNCStaticMap1.GetStaticMap(LCenter, 640, 480, 11, False, mtSatellite));
  Memo1.Lines.Add(TMSFNCStaticMap1.GetStaticMap(LCenter, 640, 480, 11, False, mtHybrid));
  Memo1.Lines.Add(TMSFNCStaticMap1.GetStaticMap(LCenter, 640, 480, 11, False, mtTerrain));
  Memo1.Lines.Add(TMSFNCStaticMap1.GetStaticMap(LCenter, 640, 480, 11, False, mtLight));
  Memo1.Lines.Add(TMSFNCStaticMap1.GetStaticMap(LCenter, 640, 480, 11, False, mtDark));
end;

See also