PHP code example of restruct / silverstripe-latlongfield

1. Go to this page and download the library: Download restruct/silverstripe-latlongfield library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

restruct / silverstripe-latlongfield example snippets


use Restruct\SilverStripe\Forms\LatLongField;

$fields->addFieldToTab('Root.Main', $gps = LatLongField::create('GPS', 'Position (lat.,long.)'));

$gps->setAddressInputFields(['StreetAddress', 'Postcode', 'City']);
// or one at a time, by name or by field
$gps->addAddressInputField('StreetAddress');
$gps->addAddressInputField($cityField);

$gps->setLocationPickerOptions([
    'defaultLat' => 52.16502,   // where the map opens when the field is empty (default: Rotterdam)
    'defaultLng' => 4.48318,
    'defaultZoom' => 12,        // default 15
    'maptype' => 'SATELLITE',   // a google.maps.MapTypeId name; default ROADMAP
    'css_width' => '486px',     // popup map size and styling: css_width, css_height,
    'css_height' => '300px',    // css_backgroundColor, css_border, css_borderRadius, css_padding,
]);                             // css_position, css_marginTop, css_display

<img src="//maps.googleapis.com/maps/api/staticmap?center=Leiden+NL&size=600x600&key=$GMapsApiKey" />