bariew / yii2-google-maps-library
Yii2的Google Maps API库。
0.1.5
2015-07-16 13:45 UTC
Requires
- guzzlehttp/guzzle: >=4.0.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-16 14:59:54 UTC
README
Yii2的Google Maps API库
简介
尽管我们已经创建了一个扩展来显示符合Google政策外部的地图,并且与LeafLetJs库协同工作,但我们仍然收到了更新EGMap 扩展的请求。因此,我们认为应该更新这个库,并使其与Yii2兼容。这就是创建此扩展的原因。
不过,重要的是要注意,我们(目前)还没有时间编写关于它的良好文档。我们希望尽早发布,以防Yii2开发者项目中缺少EGMap库,并希望将其测试和错误发现反馈给我们。
GitHub仓库将持续更新,并为其使用编写良好的文档。所以请耐心等待。如果需要,任何帮助都将非常感激。
##安装
安装此扩展的最佳方式是通过composer。
运行以下命令:
php composer.phar require "2amigos/yii2-google-maps-library" "*"
或者添加以下内容到您应用程序的composer.json
文件的require部分:
"2amigos/yii2-google-maps-library" : "*"
##使用
尽管会有很多关于如何使用的示例,但以下示例将为您提供一个了解其使用的概览
use bariew\google\maps\LatLng; use bariew\google\maps\services\DirectionsWayPoint; use bariew\google\maps\services\TravelMode; use bariew\google\maps\overlays\PolylineOptions; use bariew\google\maps\services\DirectionsRenderer; use bariew\google\maps\services\DirectionsService; use bariew\google\maps\overlays\InfoWindow; use bariew\google\maps\overlays\Marker; use bariew\google\maps\Map; use bariew\google\maps\services\DirectionsRequest; use bariew\google\maps\overlays\Polygon; use bariew\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();
此扩展还具有插件架构,允许我们增强它,因此预计未来也将开发插件。
##配置
要配置Google地图密钥或其他选项,如语言、版本、库,请使用Asset Bundle定制功能。
'components' => [ 'assetManager' => [ 'bundles' => [ 'bariew\google\maps\MapAsset' => [ 'options' => [ 'key' => 'this_is_my_key', 'language' => 'id', 'version' => '3.1.18' ] ] ] ], ],
要获取密钥,请访问https://code.google.com/apis/console/
##资源
web development has never been so fun www.2amigos.us