PHPackages                             voime/yii2-google-maps - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. voime/yii2-google-maps

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

voime/yii2-google-maps
======================

Google Maps Yii2 wrapper

1.4(10y ago)513.3k↓37.5%4MITPHP

Since Mar 9Pushed 8y ago2 watchersCompare

[ Source](https://github.com/voime/yii2-google-maps)[ Packagist](https://packagist.org/packages/voime/yii2-google-maps)[ RSS](/packages/voime-yii2-google-maps/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

Google Maps Yii2 wrapper
========================

[](#google-maps-yii2-wrapper)

Google Maps Yii2 wrapper

Forked from \[\] and

- added Infowindow support.
- removed units parameters.
- added mapOptions parameters. (styles)
- added marker options. (icon)
- added mapInput widget

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

```
"voime/yii2-google-maps": "*"

```

to the require section of your `composer.json` file.

MUST READ
---------

[](#must-read)

[Google Maps JavaScript API v3](https://developers.google.com/maps/documentation/javascript/reference)

BASIC USAGE
-----------

[](#basic-usage)

Once the extension is installed, simply use it in your code by :

```
use voime\GoogleMaps\Map;

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

There are two ways to set API KEY:

Add to application parameters.

```
config/params.php

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

Or pass it direct to widget.

```
use voime\GoogleMaps\Map;

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

Parameters

NameDescriptionmapOptionsarray, not required, map object optionszoominteger, not required, default 16centerarray 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' `widthstring, not required, default 600px. div wrapper widthheightstring, not required, default 600px. div wrapper heightmapTypestring, not required, default ROADMAP. Available types: MAP\_TYPE\_ROADMAP, MAP\_TYPE\_HYBRID, MAP\_TYPE\_SATELLITE, MAP\_TYPE\_TERRAINmarkersarray, not required. Markers that will be added to mapMARKERS
-------

[](#markers)

One or more marker can be added to map. Just pass marker array to widget config

```
use voime\GoogleMaps\Map;

echo Map::widget([
    'mapOptions' => ['styles' => file_get_contents(Yii::getAlias('@webroot/res/map-styles.json'))],
    'zoom' => 5,
    'center' => [45, 45],
    'markers' => [
        ['position' => 'Tartu', 'title' => 'marker title', 'content' => 'InfoWindow content', 'options' => ["icon" => "'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'"]],
        ['position' => [56,27]],
    ]
]);
```

MARKER OPTIONS
--------------

[](#marker-options)

The following options are allowed:

NameDescriptionpositionstring or array, required. If array lat and lng will be used, if string search query will be used.titlestring, not required. Rollover textcontentstring, not required. Infowindow textoptionsarray, not required. Marker optionsMARKERS FIT BOUNDS
------------------

[](#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

```
use voime\GoogleMaps\Map;

echo Map::widget([
    'width' => '50%',
    'height' => '600px',
    'mapType' => Map::MAP_TYPE_HYBRID,
    'markers' => [
        ['position' => 'Belgrad'],
        ['position' => 'Zagreb'],
        ['position' => 'Skopje'],
        ['position' => 'Podgorica'],
        ['position' => 'Sarajevo'],
    ],
    'markerFitBounds'=>true
]);
```

MAPINPUT
--------

[](#mapinput)

MapInput widget example. This need the following inputs

- address-input for address seach on map
- lat-input for latitude
- lng-input for longitude
- country-input for country name \[optional\]

```
use voime\GoogleMaps\MapInput;
