2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-geocodefield

Silverstripe field for fetching geo data from google maps api for any addresses

image

nblum/silverstripe-geocodefield

Silverstripe field for fetching geo data from google maps api for any addresses

  • Wednesday, March 14, 2018
  • by nblum
  • Repository
  • 1 Watchers
  • 2 Stars
  • 149 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 77 % Grown

The README.md

silverstripe-geocodefield

Fetches the geo position (lon,lat) from google maps api. Can be used as free address input field or referenced to other address fields in form, (*1)

Requirements

  • Silverstripe 4.* or Silverstripe 3.*(use tag 0.3.0 for v3.x support)

Installation

Composer

  • composer require "nblum/silverstripe-geocodefield"

Manual

  • Download/Clone module in SilverStripe root directory

Usage

Configuration:, (*2)

You may need to provide an api key from google (Geolocation API), (*3)

Nblum\Geocodefield\Forms\GeoCodeField:
  google_api_key: 'your_google_maps_api_ke'

...or try to geocode with Nominatim from OpenStreetMap https://wiki.openstreetmap.org/wiki/Nominatim, (*4)

Nblum\Geocodefield\Forms\GeoCodeField:
  custom_geocoder: 'osm'

Basic Example:, (*5)


class MyPage extends Page { private static $db = array( 'Geodata' => \Nblum\Geocodefield\Forms\Json::class ); public function getCMSFields() { $fields = parent::getCMSFields(); //creates a GeoCodeField field $fields->addFieldToTab('Root.Main', new \Nblum\Geocodefield\Forms\GeoCodeField('Geodata')); return $fields; } }

Example with referenced address fields:, (*6)


class MyPage extends Page { private static $db = array( 'Street' => 'Varchar', 'City' => 'Varchar', 'Geodata' => 'Json' ); public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Main', new TextField('Street')); $fields->addFieldToTab('Root.Main', new TextField('City')); //creates a GeoCodeField field $field = new \Nblum\Geocodefield\Forms\GeoCodeField('Geodata', 'Geo Position'); $field->addAddressReference('Street'); $field->addAddressReference('City'); $field->setAddressNotEditable(); $fields->addFieldToTab('Root.Main', $field); return $fields; } }

Write lon/lat values to separate db columns, (*7)


class MyPage extends Page { private static $db = array( 'Lat' => 'Varchar', 'Lon' => 'Varchar', 'GeoData' => 'Json' ); public function getCMSFields() { //... } protected function onBeforeWrite() { parent::onBeforeWrite(); //get current values and update some custom fields $parts = json_decode($this->getField('GeoData')); $this->setField('Lat', $parts->lat); $this->setField('Lon', $parts->lon); } }

The Versions

14/03 2018

dev-master

9999999-dev

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/03 2018

2.0.3

2.0.3.0

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/03 2018

2.0.2

2.0.2.0

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/03 2018

2.0.1

2.0.1.0

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/03 2018

2.0.0

2.0.0.0

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/03 2018

0.3.0

0.3.0.0

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/03 2018

dev-migrate/v4

dev-migrate/v4

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/03 2018

0.4.0

0.4.0.0

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode

14/10 2016

dev-ss3.x

dev-ss3.x

Silverstripe field for fetching geo data from google maps api for any addresses

  Sources   Download

MIT

The Requires

 

geolocation silverstripe input geocode