2017 © Pedro Peláez
 

yii-extension yii2-google-maps-library

Google Maps API library for Yii2.

image

2amigos/yii2-google-maps-library

Google Maps API library for Yii2.

  • Wednesday, April 25, 2018
  • by tonydspaniard
  • Repository
  • 33 Watchers
  • 85 Stars
  • 80,050 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 73 Forks
  • 45 Open issues
  • 13 Versions
  • 9 % Grown

The README.md

yii2-google-maps-library

Google Maps API library for Yii2, (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Introduction

Even though we already created an extension to display maps that are away from Google's policies and works with LeafLetJs library, we still received requests to have EGMap extension for Yii1 updated. So we thought that we should update this library and make it work with Yii2 if we were to update it. Thats the reason behind the creation of this extension., (*3)

Nevertheless, it is important to note that we didn't have time (yet) to write any good documentation about it. We wanted to publish it already, just in case somebody working with Yii2 was missing the EGMap library for its projects, and wishes to update us with its tests and bug findings., (*4)

The github repository will keep being updated, and documentation well written for its usage. So please, do not be impatient. If you do, any help will be highly appreciated., (*5)

Installation

The preferred way to install this extension is through composer., (*6)

Either run, (*7)

php composer.phar require "2amigos/yii2-google-maps-library" "*"

or add, (*8)

"2amigos/yii2-google-maps-library" : "*"

to the require section of your application's composer.json file., (*9)

Usage

Even though there will be plenty of examples on how to use it, here is one that will provide you with a glimpse of its usage:, (*10)

Service

use dosamigos\google\maps\LatLng;
use dosamigos\google\maps\services\DirectionsWayPoint;
use dosamigos\google\maps\services\TravelMode;
use dosamigos\google\maps\overlays\PolylineOptions;
use dosamigos\google\maps\services\DirectionsRenderer;
use dosamigos\google\maps\services\DirectionsService;
use dosamigos\google\maps\overlays\InfoWindow;
use dosamigos\google\maps\overlays\Marker;
use dosamigos\google\maps\Map;
use dosamigos\google\maps\services\DirectionsRequest;
use dosamigos\google\maps\overlays\Polygon;
use dosamigos\google\maps\layers\BicyclingLayer;

$coord = new LatLng(['lat' => 39.720089311812094, 'lng' => 2.91165944519042]);
$map = new Map([
    'center' => $coord,
    'zoom' => 14,
]);

// lets use the directions renderer
$home = new LatLng(['lat' => 39.720991014764536, 'lng' => 2.911801719665541]);
$school = new LatLng(['lat' => 39.719456079114956, 'lng' => 2.8979293346405166]);
$santo_domingo = new LatLng(['lat' => 39.72118906848983, 'lng' => 2.907628202438368]);

// setup just one waypoint (Google allows a max of 8)
$waypoints = [
    new DirectionsWayPoint(['location' => $santo_domingo])
];

$directionsRequest = new DirectionsRequest([
    'origin' => $home,
    'destination' => $school,
    'waypoints' => $waypoints,
    'travelMode' => TravelMode::DRIVING
]);

// Lets configure the polyline that renders the direction
$polylineOptions = new PolylineOptions([
    'strokeColor' => '#FFAA00',
    'draggable' => true
]);

// Now the renderer
$directionsRenderer = new DirectionsRenderer([
    'map' => $map->getName(),
    'polylineOptions' => $polylineOptions
]);

// Finally the directions service
$directionsService = new DirectionsService([
    'directionsRenderer' => $directionsRenderer,
    'directionsRequest' => $directionsRequest
]);

// Thats it, append the resulting script to the map
$map->appendScript($directionsService->getJs());

// Lets add a marker now
$marker = new Marker([
    'position' => $coord,
    'title' => 'My Home Town',
]);

// Provide a shared InfoWindow to the marker
$marker->attachInfoWindow(
    new InfoWindow([
        'content' => '

This is my super cool content, (*11)

' ]) ); // Add marker to the map $map->addOverlay($marker); // Now lets write a polygon $coords = [ new LatLng(['lat' => 25.774252, 'lng' => -80.190262]), new LatLng(['lat' => 18.466465, 'lng' => -66.118292]), new LatLng(['lat' => 32.321384, 'lng' => -64.75737]), new LatLng(['lat' => 25.774252, 'lng' => -80.190262]) ]; $polygon = new Polygon([ 'paths' => $coords ]); // Add a shared info window $polygon->attachInfoWindow(new InfoWindow([ 'content' => '

This is my super cool Polygon, (*12)

' ])); // Add it now to the map $map->addOverlay($polygon); // Lets show the BicyclingLayer :) $bikeLayer = new BicyclingLayer(['map' => $map->getName()]); // Append its resulting script $map->appendScript($bikeLayer->getJs()); // Display the map -finally :) echo $map->display();

Client

use dosamigos\google\maps\services\DirectionsClient;

$direction = new DirectionsClient([
    'params' => [
        'language' => Yii::$app->language,
        'origin' => 'street from',
        'destination' => 'street to'
    ]
]);

$data = $direction->lookup(); //get data from google.maps API

This extension has also a plugin architecture that allow us to enhance it, so expect plugins to be developed in near future too., (*13)

Configuration

To configure the Google Map key or other options like language, version, library, use the Asset Bundle customization feature., (*14)

'components' => [
    'assetManager' => [
        'bundles' => [
            'dosamigos\google\maps\MapAsset' => [
                'options' => [
                    'key' => 'this_is_my_key',
                    'language' => 'id',
                    'version' => '3.1.18'
                ]
            ]
        ]
    ],
],

To get key, please visit https://code.google.com/apis/console/, (*15)

Using code sniffer

Once you do composer install -o, the php-cs-fixer tool will be added to your vendor file. To fix the formatting of your php files, simply do:, (*16)

 ./vendor/bin/php-cs-fixer --config=.php_cs.dist fix

Resources

2amigOS!
beyond software
www.2amigos.us, (*17)

The Versions

25/04 2018

dev-master

9999999-dev

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

26/03 2018

1.1.7

1.1.7.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

21/03 2018

1.1.6

1.1.6.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

07/03 2018

1.1.5

1.1.5.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

02/03 2018

1.1.4

1.1.4.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

16/01 2018

1.1.3

1.1.3.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

11/10 2016

1.0.2

1.0.2.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

10/05 2016

1.0.1

1.0.1.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

30/10 2015

1.0.0

1.0.0.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

15/05 2015

dev-develop

dev-develop https://github.com/2amigos/yii2-google-maps-library

The Google Maps API library for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Alexander Kochetov

yii2 2amigos yii google maps yii 2

09/12 2014

0.1.2

0.1.2.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

17/10 2014

0.1.1

0.1.1.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps

25/09 2014

0.1.0

0.1.0.0

Google Maps API library for Yii2.

  Sources   Download

BSD-3-Clause

The Requires

 

extension library yii google maps