2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-googlemapfield

Save locations using latitude/longitude DataObject fields.

image

betterbrief/silverstripe-googlemapfield

Save locations using latitude/longitude DataObject fields.

  • Wednesday, January 10, 2018
  • by betterbrief
  • Repository
  • 5 Watchers
  • 12 Stars
  • 34,062 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 13 Forks
  • 3 Open issues
  • 15 Versions
  • 9 % Grown

The README.md

silverstripe-googlemapfield

Scrutinizer Code Quality, (*1)

Lets you record a precise location using latitude/longitude/zoom fields to a DataObject., (*2)

Displays a map using the Google Maps API. The user may then choose where to place the marker; the landing coordinates are then saved., (*3)

You can also search for locations using the search box, which uses the Google Maps Geocoding API., (*4)

Supports SilverStripe 4, (*5)

Usage

Minimal configuration

Given your DataObject uses the field names Latitude and Longitude for storing the latitude and longitude respectively then the following is a minimal setup to have the map show in the CMS:, (*6)

use SilverStripe\ORM\DataObject;
use BetterBrief\GoogleMapField;

class Store extends DataObject
{
    private static $db = [
        'Title' => 'Varchar(255)',
        'Latitude' => 'Varchar',
        'Longitude' => 'Varchar',
    ];

    public function getCMSFields() {
        $fields = parent::getCMSFiels();

        // add the map field
        $fields->addFieldToTab('Root.Main', new GoogleMapField(
            $this,
            'Location'
        ));

        // remove the lat / lng fields from the CMS
        $fields->removeFieldsFromTab('Root.Main', ['Latitude', 'Longitude']);

        return $fields;
    }
}

Remember to set your API key in your site's config.yml, (*7)

BetterBrief\GoogleMapField:
  default_options:
    api_key: '[google-api-key]'

Optional configuration

Configuration options

You can either set the default options in your yaml file (see _config/googlemapfield.yml for a complete list) or at run time on each instance of the GoogleMapField object., (*8)

Setting at run time

To set options at run time pass through an array of options (3rd construct parameter):, (*9)

use BetterBrief\GoogleMapField;

$field = new GoogleMapField(
    $dataObject,
    'FieldName',
    [
        'api_key' => 'my-api-key',
        'show_search_box' => false,
        'map' => [
            'zoom' => 10,
        ],
        ...
    ]
);

Customising the map appearance

You can customise the map's appearance by passing through settings into the map key of the $options (shown above). The map settings take a literal representation of the google.maps.MapOptions, (*10)

For example if we wanted to change the map type from a road map to satellite imagery we could do the following:, (*11)

use BetterBrief\GoogleMapField;

$field = new GoogleMapField(
    $object,
    'Location',
    [
        'map' => [
            'mapTypeId' => 'SATELLITE',
        ],
    ]
);

Getting an API key

Google Maps API key

To get a Google Maps JS API key please see the official docs, (*12)

To use the search box to find locations on the map, you'll need to have enabled the Geocoding API as well. Please see the official docs, (*13)

The Versions

10/01 2018

dev-master

9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

10/01 2018

2.x-dev

2.9999999.9999999.9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

10/01 2018

v2.1.0

2.1.0.0 http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

10/01 2018

v2.1.0-beta

2.1.0.0-beta http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

2.0.0-rc.1

2.0.0.0-RC1 http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.x-dev

1.9999999.9999999.9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.4.x-dev

1.4.9999999.9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.4.0

1.4.0.0 http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.3.x-dev

1.3.9999999.9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.3.1

1.3.1.0 http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.2.x-dev

1.2.9999999.9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.1.x-dev

1.1.9999999.9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

28/11 2017

1.0.x-dev

1.0.9999999.9999999-dev http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

06/02 2015

1.3

1.3.0.0 http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield

30/06 2014

v1.2

1.2.0.0 http://github.com/BetterBrief/googlemapfield

Save locations using latitude/longitude DataObject fields.

  Sources   Download

BSD

The Requires

 

geolocation google maps silverstripe map googlemapfield