2amigos/yii2-google-maps-library
最新稳定版本:1.1.9
Composer 安装命令:
composer require 2amigos/yii2-google-maps-library
包简介
Google Maps API library for Yii2.
关键字:
README 文档
README
Google Maps API library for Yii2
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
beyond software
www.2amigos.us
2amigos/yii2-google-maps-library 适用场景与选型建议
2amigos/yii2-google-maps-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 388.81k 次下载、GitHub Stars 达 106, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「extension」 「google」 「maps」 「yii」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 2amigos/yii2-google-maps-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 2amigos/yii2-google-maps-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 2amigos/yii2-google-maps-library 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
Inbox pattern process implementation for your Laravel Applications
统计信息
- 总下载量: 388.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 110
- 点击次数: 19
- 依赖项目数: 14
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-04