Skip to content

Markers ​

A marker is a pin on the map with a text, and, if you want, a label, an animation and an info window that opens on a click.

pascal
var
  Position: TLatLng;
begin
  Position.Latitude := -31.9523;
  Position.Longitude := 115.8613;
  EdgeGoogleMapViewer.PutMarker(Position, 'Perth, Western Australia');
end;

PutMarker ​

pascal
procedure PutMarker(LatLng: TLatLng; ADescription: string;
  AAnimation: TGoogleMarkerAnimationId = maNONE; ALabel: string = '';
  AInfoWindowContent: string = ''; ACustomMarkerJSON: string = '');
Parameter
ADescriptionThe text of the marker (its title)
AAnimationmaNONE, maBOUNCE or maDROP
ALabelA short text drawn on the marker
AInfoWindowContentHTML shown in a window when the user clicks the marker. If you give neither this nor an info title, the window shows the description
ACustomMarkerJSONA marker of your own drawing, see below

A second overload adds AInfoTitle, the bold header of the info window, between ADescription and AAnimation:

pascal
EdgeGoogleMapViewer.PutMarker(Position, 'Perth', 'Perth, Western Australia', maDROP,
  '', '<p>The capital of <b>Western Australia</b>.</p>');

The map uses the new AdvancedMarkerElement of Google Maps and falls back to the classic Marker when the new one is not available, and whenever the marker has an animation, a label or a custom drawing.

Markers by address ​

PutMarkerByAddress looks the address up with the Google geocoding service and puts the marker where it is, so you do not need its coordinates:

pascal
EdgeGoogleMapViewer.PutMarkerByAddress('Via Santa Cecilia 4, Carugate, Milano',
  'Our office', '<p>Open from 9 to 18</p>');

The calls are throttled by the component (batches of 5, with 300 ms between them) so that a loop that adds many markers does not exceed the rate Google allows.

Markers added while scrolling a table of customers

Custom markers ​

ACustomMarkerJSON is a JSON object that describes a Google Maps Symbol: an SVG path, the colours, the stroke and the scale. DefaultCustomMarkerJSON returns an example you can start from:

json
{
  "path": "M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z M -2,-30 a 2,2 0 1,1 4,0 2,2 0 1,1 -4,0",
  "fillColor": "#00D800",
  "fillOpacity": 1,
  "strokeColor": "#000",
  "strokeWeight": 2,
  "scale": 1
}
pascal
EdgeGoogleMapViewer.PutMarker(Position, 'Here', maNONE, '', '',
  EdgeGoogleMapViewer.DefaultCustomMarkerJSON);

Removing and hiding ​

Call
ClearMarkersRemoves every marker
HideMarkersHides them, keeping them
ShowMarkersShows them again

Text and HTML

The description, the label and the info window content are passed to the page as properly escaped JavaScript strings, so a quote or </script> in a customer's name is harmless. The info window content is HTML: if it comes from your users, escape it yourself before you use it.

Released under the Apache License 2.0