Download the PHP package restruct/silverstripe-latlongfield without Composer

On this page you can find all versions of the php package restruct/silverstripe-latlongfield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package silverstripe-latlongfield

Simple Silverstripe Latlong Field

Maintained by Restruct. If this module saves you time, you can support ongoing maintenance.

Screenshot 2021-02-27 at 16 22 59

CMS editor can type street address, then click search. A (draggable) pointer will be shown on a map and the field's content will be replaced with the LatLong code. Originally abstracted from the mappable module (I think).

The value is stored as a plain "lat,long" string (eg. 52.16502,4.48318), so any text column (Varchar) will do. The class also carries a few static helpers for such strings: validation, distance between two coordinates, and server-side geocoding.

Requirements

Installation

Version compatibility

Branch Module version Silverstripe PHP
main 2.x ^5 \|\| ^6 ^8.1
v1 1.0.6 - 1.0.7 ^4 \|\| ^5 not declared
(tags only) 1.0.0 - 1.0.5 4 (not declared) not declared

composer.json is the source of truth; this table is a convenience copy. Silverstripe 4 reached end of life in April 2025 and is no longer supported or tested here. Projects still on it should stay on the 1.x tags, which remain available; v1 takes bug fixes only. Upgrading from 1.x: see UPGRADING.md.

Config

GeoCode() waits at most geocode_timeout seconds (default 5) for Google, for the connect and for each read:

SS3-4 upgrade: moved LatLongField::google_maps_api_key to environment var (see Config above)

Usage

Without address fields, the editor types an address into the field itself and clicks the search button; the map opens and the field's value is replaced with the coordinates. The marker can be dragged, or the map double-clicked, to adjust them. The "x" (clear) button clears the value.

Look up the address from other fields

Point the field at the form fields that hold the address. It then becomes read-only, and the search button geocodes the combined value of those fields:

setAddressInputFields() replaces the list; addAddressInputField() appends to it.

Map options

Options are passed to the bundled jQuery location picker (client/js/jquery.locationpicker.js). setLocationPickerOptions() merges into what is already set:

Defaults the field sets

When it renders, the field adds a text class (for CMS styling), a placeholder ((empty / no location yet)) unless one is set, and a description with instructions unless it already has a description or a right title.

Provides global $GMapsApiKey template variable

$GMapsApiKey is the browser key when one is set (see Config).

Static helpers

Method Returns
LatLongField::validateLatLong($value) true for a "lat,long" string with numeric parts, latitude -90..90 and longitude -180..180 (whitespace around the parts is allowed)
LatLongField::calCulateDistance($from, $to, $decimals = 0) distance in km between two "lat,long" strings (haversine), rounded to $decimals; null if either is not a valid coordinate
LatLongField::GeoCode($address) the first result of the Google Geocoding API for $address as an array (geometry.location holds lat/lng), or null on any failure. Uses GMAPS_API_KEY, never the browser key. A failed request (network error, timeout, a response that is not JSON, a status other than OK or ZERO_RESULTS) is logged as a warning through Psr\Log\LoggerInterface (the failure kind or API status, the HTTP status line if a response arrived, and the timeout; never the address, the URL or the key), and raises no PHP warning. Without GMAPS_API_KEY it raises an E_USER_NOTICE and returns null
LatLongField::gmaps_api_key($requirePrimaryKey = false) the browser key if set, else GMAPS_API_KEY; with true, always GMAPS_API_KEY

Assets

Rendering the field (Field(), so also FieldHolder() and a form template) adds these requirements to the page. Constructing it adds nothing, so building a form or getCMSFields() without rendering it (exports, API responses) does not queue them:

client/ is exposed through extra.expose in composer.json, so the files are published under _resources/ by silverstripe/vendor-plugin.

Running the tests

The suite needs a booted Silverstripe project. Require the module into one through a symlinked path repository (/tests is export-ignore, so a dist install has no tests), add silverstripe/recipe-testing (and silverstripe/cms for the CMS render test, which is skipped without it), copy phpunit.xml.dist to the project root, then:

.github/workflows/ci.yml builds exactly such a host project for each supported major.


All versions of silverstripe-latlongfield with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
silverstripe/framework Version ^5 || ^6
silverstripe/vendor-plugin Version ^2 || ^3
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package restruct/silverstripe-latlongfield contains the following files

Loading the files please wait ...