2017 © Pedro Peláez
 

yii2-extension yii2-google-maps

Google Maps Yii2 wrapper

image

tugmaks/yii2-google-maps

Google Maps Yii2 wrapper

  • Wednesday, October 7, 2015
  • by tugmaks
  • Repository
  • 0 Watchers
  • 3 Stars
  • 7,948 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 2 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Google Maps Yii2 wrapper

Google Maps Yii2 wrapper, (*1)

Installation

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

Either run, (*3)

php composer.phar require --prefer-dist tugmaks/yii2-google-maps "*"

or add, (*4)

"tugmaks/yii2-google-maps": "*"

to the require section of your composer.json file., (*5)

MUST READ

Google Maps JavaScript API v3, (*6)

BASIC USAGE

Once the extension is installed, simply use it in your code by :, (*7)

use tugmaks\GoogleMaps\Map;

echo Map::widget([
    'zoom' => 16,
    'center' => 'Red Square',
    'width' => 700,
    'height' => 400,
    'mapType' => Map::MAP_TYPE_SATELLITE,
]);

There are two ways to set API KEY:, (*8)

Add to application parameters., (*9)

config/params.php

return [
.....
'GOOGLE_API_KEY' => 'VIza7yBgBzYEbKx09V566DhM8Ylc3NjWsJ0ps-2' // use your own api key
.....
]

Or pass it direct to widget., (*10)

use tugmaks\GoogleMaps\Map;

echo Map::widget([
    'apiKey'=> 'VIza7yBgBzYEbKx09V566DhM8Ylc3NjWsJ0ps-2',
    'zoom' => 3,
    'center' => [20, 40.555],
    'width' => 700,
    'height' => 400,
    'mapType' => Map::MAP_TYPE_HYBRID,
]);

Parameters, (*11)

Name Description
zoom integer, not required, default 16
center array or string, required. If array lat and lng will be used, if string search query will be used. For example: php 'center'=>[23.091,100.412] or php 'center'=>'London, UK'
width integer, not required, default 600. Size in $widthUnits default 'px' of div wrapper width
height integer, not required, default 600. Size in $heightUnits default 'px' of div wrapper height
widthUnits string, not required, default UNITS_PX. Available types: UNITS_PX, UNITS_PERCENT, UNITS_EM, UNITS_REM, UNITS_VH,UNITS_VW
heightUnits string, not required, default UNITS_PX. Available types: UNITS_PX, UNITS_PERCENT, UNITS_EM, UNITS_REM, UNITS_VH,UNITS_VW
mapType string, not required, default ROADMAP. Available types: MAP_TYPE_ROADMAP, MAP_TYPE_HYBRID, MAP_TYPE_SATELLITE, MAP_TYPE_TERRAIN
markers array, not required. Markers that will be added to map

MARKERS

One or more marker can be added to map. Just pass marker array to widget config, (*12)

```php use tugmaks\GoogleMaps\Map;, (*13)

echo Map::widget([ 'zoom' => 5, 'center' => [45, 45], 'width' => 1100, 'height' => 600, 'mapType' => Map::MAP_TYPE_HYBRID, 'markers' => [ ['position' => 'Erevan'], ['position' => 'Moscow'], ['position' => 'Ankara'], ['position' => 'Kazan'], ['position' => 'Sofia'], ] ]); ````, (*14)

MARKER OPTIONS

The following options are allowed:, (*15)

Name Description
position string or array, required. If array lat and lng will be used, if string search query will be used.
title string, not required. Rollover text

MARKERS FIT BOUNDS

Sometimes you need to show all markers on map, but do not know initial map center and zoom. In this case use widget like this, (*16)

```php use tugmaks\GoogleMaps\Map;, (*17)

echo Map::widget([ 'width' => 1100, 'height' => 600, 'mapType' => Map::MAP_TYPE_HYBRID, 'markers' => [ ['position' => 'Belgrad'], ['position' => 'Zagreb'], ['position' => 'Skopje'], ['position' => 'Podgorica'], ['position' => 'Sarajevo'], ], 'markerFitBounds'=>true ]);, (*18)

The Versions

07/10 2015

dev-master

9999999-dev

Google Maps Yii2 wrapper

  Sources   Download

MIT

The Requires

 

by Maxim Tugaev

extension yii2