LocationVendorGoogle

Reference for the LocationVendorGoogle module: render Google static map URLs from a location, and convert location coordinate, address and marker data objects into the Google Maps JSON and HTML attribute shapes a page needs.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes

LocationVendorGoogleService

Static functions that turn framework location data objects into the forms Google Maps uses: a static map image URL, JSON payloads, and HTML data attributes for coordinates, addresses and markers.

AddressToGoogleJson

LocationVendorGoogleService::AddressToGoogleJson(LocationAddressData $address): string

Convert a LocationAddressData to Google Maps JSON format.

NameTypeDescription
$addressLocationAddressDataThe address to convert.

Returns string The address as a JSON string.

AddressToHtmlAttributes

LocationVendorGoogleService::AddressToHtmlAttributes(LocationAddressData $address): string

Convert a LocationAddressData to HTML attributes for Google Maps.

NameTypeDescription
$addressLocationAddressDataThe address to convert.

Returns string A space-separated string of HTML data attributes.

CoordinateToGoogleJson

LocationVendorGoogleService::CoordinateToGoogleJson(LocationCoordinateData $coordinate): string

Convert a LocationCoordinateData to Google Maps JSON format, as lat and lng.

NameTypeDescription
$coordinateLocationCoordinateDataThe coordinate to convert.

Returns string The coordinate as a JSON string with lat and lng keys.

CoordinateToHtmlAttributes

LocationVendorGoogleService::CoordinateToHtmlAttributes(LocationCoordinateData $coordinate): string

Convert a LocationCoordinateData to HTML attributes for Google Maps.

NameTypeDescription
$coordinateLocationCoordinateDataThe coordinate to convert.

Returns string The latitude and longitude as HTML data attributes.

MarkerToHtmlAttributes

LocationVendorGoogleService::MarkerToHtmlAttributes(LocationMarkerData $marker): string

Convert a LocationMarkerData to HTML attributes for Google Maps.

NameTypeDescription
$markerLocationMarkerDataThe marker to convert.

Returns string A space-separated string of HTML data attributes, including title and snippet when present.

MarkerToJavaScriptObject

LocationVendorGoogleService::MarkerToJavaScriptObject(LocationMarkerData $marker): string

Convert a LocationMarkerData to a JavaScript object for Google Maps.

NameTypeDescription
$markerLocationMarkerDataThe marker to convert.

Returns string The marker as a JSON string, including title and snippet when present.

StaticMapUrl

LocationVendorGoogleService::StaticMapUrl(LocationData $location, int $width, int $height): string

Build a Google Maps static map image URL for a location, with a red marker on its coordinate. The Google API key is read from the Location module configuration.

NameTypeDescription
$locationLocationDataThe location to map, whose coordinate centres the image.
$widthintThe image width in pixels.
$heightintThe image height in pixels.

Returns string The static map image URL.