Map

Embeds a Google Maps instance for displaying GPS coordinates as pins. Accepts coordinates directly from the Address component's getCoordinates() API or any other source. The two components are intentionally independent — wiring them together is done in application-level JS.

API Key required. A Google Maps JavaScript API key must be provided via ->apiKey(). The demos below will show a placeholder until a valid key is configured. Get an API key →

Static Map with Marker

Pre-set centre and a marker via PHP fluent API. Renders immediately on page load.

Loading map…
PHP

Multiple Markers

Pass an array of markers to ->markers(). Each must have lat, lng, and optional title.

Loading map…
PHP

Dynamic Marker Management

Use the JS API to add, clear, and re-centre the map at runtime.

Loading map…
Click a button to interact with the map...
PHP

Address Picker + Map Workflow

The Address component now exposes getCoordinates() — returns {lat, lng} if the selected address suggestion includes GPS data, or null otherwise. This example shows how to wire an address picker to a map in application JS.

PHP

Recenter Button

Enable ->recenterButton() to add a crosshairs button to the map. Clicking it resets the viewport back to the original centre coordinates and zoom level supplied at initialisation. Implemented as a native Leaflet control (bottom-left) — consistent with Leaflet's built-in zoom controls.

Loading map…

Pan or zoom the map, then click the button in the bottom-left to reset. The recenter() JS method does the same programmatically.

PHP

PHP PHP Methods (Fluent)

Method / PropertyParametersDescription
$m->map($id)stringCreate a map component.
->provider($name)stringMap provider: 'leaflet' (default, free) or 'google'.
->apiKey($key)stringGoogle Maps JavaScript API key. Required when provider = 'google'.
->center($lat, $lng)float, floatDefault map centre coordinates. Defaults to Wellington, NZ if not set.
->zoom($zoom)intInitial zoom level (1–21). Default: 14.
->height($css)stringContainer height as a CSS value. Default: '400px'.
->marker($lat, $lng, $title)float, float, stringAdd a single initial marker. $title optional; shown in info window on click.
->markers($array)arraySet all initial markers at once. Each element: ['lat' => …, 'lng' => …, 'title' => …].
->recenterButton()boolShow a recenter button on the map. Click resets the view to the original centre and zoom. Default: false.

JS JS Methods

Method / PropertyParametersDescription
m.map(id)stringGet the map API instance (auto-initialised on DOMContentLoaded).
setCenter(lat, lng)float, floatPan the map to the given coordinates.
setZoom(zoom)intSet the zoom level.
recenter()Reset the map to the original centre coordinates and zoom level.
addMarker(lat, lng, title)float, float, ?stringAdd a pin at the given coordinates. Returns the native marker instance.
clearMarkers()Remove all pins from the map.
getMarkers()Returns an array of {lat, lng, title, marker} objects.
fitMarkers()Adjust the map bounds to fit all current markers.

JS Address Component Extension

Method / PropertyParametersDescription
m.address(id).getCoordinates()Returns {lat, lng} if the selected suggestion includes GPS coordinates, or null.

EVENT Events

Event NameDetailDescription
m:map:ready{map}Fired once Google Maps has initialised. detail.map is the raw google.maps.Map instance.
m:map:markeradded{lat, lng, title}Fired after each addMarker() call.
m:map:markerscleared{}Fired after clearMarkers().