• This repository has been archived on 27/Jul/2023
  • Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    PHP
  • License
    BSD 3-Clause "New...
  • Created about 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Google Maps API library for Yii2

yii2-google-maps-library

Google Maps API library for Yii2

Latest Stable Version Total Downloads Latest Unstable Version License

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.

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.

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.

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your application's composer.json file.

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:

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' => '<p>This is my super cool content</p>'
    ])
);

// 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' => '<p>This is my super cool Polygon</p>'
    ]));

// 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.

Configuration

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

'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/

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:

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

Resources

2amigOS!
beyond software
www.2amigos.us

More Repositories

1

yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension
PHP
292
star
2

yii2-file-upload-widget

BlueImp File Upload Widget for Yii2
PHP
252
star
3

qrcode-library

Create QrCodes with ease
PHP
222
star
4

yii2-ckeditor-widget

CKEditor WYSIWYG widget for Yii2.
PHP
172
star
5

yiiwheels

Widget extension library for the YiiStrap extension
JavaScript
133
star
6

yii2-date-picker-widget

Bootstrap DatePicker Widget for Yii2
PHP
130
star
7

yii2-chartjs-widget

ChartJs Widget For Yii2
PHP
108
star
8

yii2-tinymce-widget

TinyMCE WYSIWYG widget for Yii2
JavaScript
100
star
9

yii2-taggable-behavior

This extension allows you to get functional for tagging.
PHP
85
star
10

yii2-selectize-widget

Selectize From Brian Reavis Yii2 Widget
PHP
73
star
11

yii2-translateable-behavior

Handles ActiveRecord's attribute translations
PHP
66
star
12

yii2-gallery-widget

BlueImp Gallery Widget for Yii2
PHP
60
star
13

yii2-editable-widget

X-Editable Widget for Yii2
PHP
58
star
14

yii2-grid-view-library

Highly enhanced GridView widget and grid components for Yii2
PHP
57
star
15

yii2-app-template

Yii 2 Basic Application Template with ConfigKit.
PHP
54
star
16

mailer-library

Mailer library with queue capabilities.
PHP
50
star
17

yii2-multi-select-widget

Bootstrap MultiSelect and MultiSelect Listbox widgets for Yii2
PHP
45
star
18

yiinitializr

Library that will help boost your application installation with ease and also to run Yii applications from its bootstrap files on a much cleaner way that the framework currently proposes.
PHP
44
star
19

yii2-date-time-picker-widget

Bootstrap DateTimePicker Widget for Yii2
PHP
44
star
20

yii2-highcharts-widget

HighCharts Js Widget for Yii2
PHP
42
star
21

yiiwheels-docs

Demo site for yii-wheels
PHP
40
star
22

yii2-resource-manager-component

Uploaded file management extension
PHP
35
star
23

2fa-library

2 Factor Authentication (2FA) library
PHP
34
star
24

yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
PHP
30
star
25

embeddable-js-widget-template

How to create an embeddable JS widget
JavaScript
27
star
26

yii2-transliterator-helper

TransliteratorHelper transliterates UTF-8 encoded text to US-ASCII
PHP
26
star
27

yii2-semantic-ui

Yii2 Semantic UI Extension
PHP
25
star
28

yii2-disqus-widget

DISQUS widget for Yii2
PHP
25
star
29

yii2-config-kit

Configuration kit for Yii applications
PHP
24
star
30

ei18n

Ei18 is a translation module to allow Yii'ers to easily manage missing translations on application pages. It is heavily inspired by yii.translate developed by Gustavo Salomรฉ Silva.
JavaScript
24
star
31

yii2-type-ahead-widget

Twitter Typeahead Bootstrap Widget
PHP
23
star
32

yii2-file-input-widget

Jasny File Input Bootstrap Widget
PHP
23
star
33

mail-api-service

A microservice to send emails based on templates.
PHP
23
star
34

yii2-google-places-library

Google Places API library for Yii2
PHP
23
star
35

yiifoundation

Yii extension library for the ZURB Foundation Framework
CSS
22
star
36

yii2-flysystem-component

The League Flysystem Library for Yii Framework
PHP
22
star
37

yiiaws

Amazon Web Services SDK PHP 2 Wrapper
PHP
21
star
38

yii2-arrayquery-component

ArrayQuery allows you to apply conditions to arrays that are to be displayed with ArrayDataProviders
PHP
21
star
39

yii2-exportable-widget

Allows the exportation of a GridView widget to different formats
PHP
20
star
40

yii2-switch-widget

Bootstrap Switch Widget for Yii2
PHP
17
star
41

egmap

Objet-oriented PHP abstraction to the Google Maps API to ease the process of adding a Google Map on your Yii projects.
PHP
14
star
42

efeed

Feed Writer Generator Extension (RSS 1.0, RSS 2.0, and ATOM 1.0)
PHP
12
star
43

yii-cdn-asset-management-library

CDN Asset Management Tools for Yii1
PHP
12
star
44

yii2-croppie-widget

Image cropping plugin for Yii2
PHP
11
star
45

yii2-dynamic-form

JavaScript
10
star
46

escriptboost

Minify the javascript/css code of your application's assets and pages
PHP
9
star
47

storage-api-service

A microservice that abstracts asset storage on different providers
PHP
9
star
48

google-places-library

Google Places API library
PHP
9
star
49

egeoip

EGeoIp Extension uses geoPlugin free webservice to locate IP geo information
PHP
9
star
50

yii2-bootstrap-form-helpers-library

Bootstrap Form Helpers Library Widgets for Yii2.
JavaScript
8
star
51

yii2-extension-skeleton

A skeleton repository for Yii2 Skeleton Packages
PHP
8
star
52

yii2-switchery-widget

Yii2 wrapper for iOS 7 style switches for your checkboxes
PHP
7
star
53

yii2-app-usuario-template

Yii 2 Basic Application Template with ConfigKit and Yii 2 Usuario Module
PHP
7
star
54

yii2-select2-widget

Select 2 jQuery plugin for Yii2 with Bootstrap theme capabilities
PHP
7
star
55

yiiwheels-custom

Yiiwheels custom library. Removes Yiistrap dependency and implements Yii2 based bootstrap library to be used on Yii1.
JavaScript
6
star
56

yiihelpers

A library of useful Helper functions to give your apps an extra hand.
PHP
6
star
57

transliteration-helper

TransliteratorHelper transliterates UTF-8 encoded text to US-ASCII
PHP
5
star
58

yii2-twilio-component

A Yii2 Application Component to ease the use of Twilio's PHP SDK
PHP
5
star
59

resource-manager

Uploaded file management extension
PHP
5
star
60

yii2-pjax-filter-behavior

PjaxFilter is an action filter that filters HTTP requests to ensure pjax calls.
PHP
4
star
61

yii2-leaflet-geocoder-plugin

Yii 2 Plugin that adds geo search capabilities to your leaflet maps with dropdown list capabilities.
PHP
4
star
62

yii2-leaflet-markercluster-plugin

Yii 2 LeafLet Plugin to provide beautiful, sophisticated, high performance marker clustering solution with smooth animations and lots of great features.
JavaScript
4
star
63

yii2-shopping-cart-component

3
star
64

yii2-dosamigos-asset-bundle

Includes assets that are common to projects using dosamigos extensions.
JavaScript
3
star
65

laravel-mail-api

A microservice to send emails based on templates.
PHP
2
star
66

yii2-nexmo-library

Allows you to send SMS through Nexmo Service Provider.
PHP
2
star
67

yii2-packagist-component

Yii 2 Packagist API extension component
PHP
1
star
68

command-bus

Simple Command Bus
PHP
1
star
69

yii2-leaflet-geosearch-plugin

Yii 2 Plugin that adds geo search capabilities to your leaflet maps.
JavaScript
1
star
70

yii2-file-manager

1
star
71

yii2-leaflet-makimarker-plugin

Yii 2 LeafLet Plugin to create map icons using Maki Icons from MapBox.
PHP
1
star