sadi01 / yii2-google-maps-library
Yii2的Google Maps API库。
1.2.3
2022-07-23 03:03 UTC
Requires
- ext-json: *
- ext-simplexml: >=7.2
- guzzlehttp/guzzle: 6.*
- yiisoft/yii2: >=2.0.13
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.10@dev
- roave/security-advisories: dev-master
README
Yii2的Google Maps API库
介绍
尽管我们已经创建了一个扩展来显示远离谷歌政策的地图,并与LeafLetJs库一起工作,但我们仍然收到了更新EGMap扩展 for Yii1的请求。因此,我们认为如果我们更新它,我们应该更新这个库并使其与Yii2一起工作。这就是这个扩展创建的原因。
尽管如此,重要的是要注意,我们还没有时间(还没有)为其编写任何好的文档。我们本想早点发布的,以防Yii2的开发者缺少EGMap库,并希望与我们分享其测试和错误发现。
github存储库将保持更新,并为其使用编写详细的文档。所以,请不要急躁。如果您愿意,任何帮助都将非常感激。
安装
通过 composer 安装此扩展是首选方式。
运行
php composer.phar require "sadi01/yii2-google-maps-library" "*"
或添加
"sadi01/yii2-google-maps-library" : "*"
到您的应用程序的 composer.json
文件的require部分。
用法
尽管将有很多使用示例,但这里有一个可以为您提供其用法的一瞥
服务
use sadi01\google\maps\LatLng; use sadi01\google\maps\services\DirectionsWayPoint; use sadi01\google\maps\services\TravelMode; use sadi01\google\maps\overlays\PolylineOptions; use sadi01\google\maps\services\DirectionsRenderer; use sadi01\google\maps\services\DirectionsService; use sadi01\google\maps\overlays\InfoWindow; use sadi01\google\maps\overlays\Marker; use sadi01\google\maps\Map; use sadi01\google\maps\services\DirectionsRequest; use sadi01\google\maps\overlays\Polygon; use sadi01\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();
客户端
use sadi01\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
此扩展还有一个插件架构,允许我们增强它,因此预计未来也将开发插件。
配置
要配置Google Map密钥或其他选项,如语言、版本、库,请使用Asset Bundle自定义功能。
'components' => [ 'assetManager' => [ 'bundles' => [ 'sadi01\google\maps\MapAsset' => [ 'options' => [ 'key' => 'this_is_my_key', 'language' => 'id', 'version' => '3.1.18' ] ] ] ], ],
获取密钥,请访问https://code.google.com/apis/console/
使用代码嗅探器
一旦你做了 composer install -o
,php-cs-fixer
工具将被添加到你的供应商文件。要修复你的PHP文件的格式,只需做
./vendor/bin/php-cs-fixer --config=.php_cs.dist fix
资源
beyond software
www.2amigos.us