其实在我们的联系页面中,我们可能会显示特定地址的地图,但在我的网站中,我有不同的用户与不同的位置,所以,当我想点击该特定用户我需要用地图显示他们的地址。 yii 2将谷歌地图模板添加到YII2高级模板
-2
A
回答
0
试试这个: Yii 2.0:yii2-google-maps-library。
安装
安装此扩展的首选方法是通过作曲家。
无论是运行
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.
即使将有大量的关于如何使用它的例子,这里是一个会为您提供其使用的一瞥:
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();
这个扩展还有一个插件体系结构,可以让我们对其进行增强,所以期望在不久的将来开发插件。
欲了解更多信息enter link description here
+0
谢谢amitesh – Baji
+0
plz接受答案并投票给我 –
相关问题
- 1. yii2 API 404 - 高级模板
- 2. Yii2高级模板配置
- 3. Yii2模块的高级模板
- 4. 在ubuntu上安装Yii2高级模板
- 5. 高级模板
- 6. 谷歌地图泡沫模板
- 7. woocommerce高级模板
- 8. Yii2 SQLSTATE [22003]在我的yii2高级模板中插入
- 9. 何时在Yii2高级模板中创建模块?
- 10. Yii2 ArrayDataProvider模板
- 11. 如何重定向到特定的方法Yii2(高级模板)?
- 12. 高级模板Yii2 - 使用htaccess重定向到前端/网页
- 13. 如何在gridview YII2高级模板中添加特定行的动作按钮?
- 14. 谷歌电视HTML5模板
- 15. 如何在高级模板
- 16. 将模板类型名称添加到两个模板类
- 17. 将谷歌地图添加到网页
- 18. 将jscrollpane添加到谷歌地图infowindow
- 19. 将GEvent addListener添加到谷歌地图
- 20. 波尔图模板:谷歌地图显示不出来
- 21. 添加HtmlAttributes到模板
- 22. 在Yii2中创建持久化的CSS和JS高级模板
- 23. Yii2前端和后端之间的链接(高级模板)
- 24. 如何只访问一个特定页面YII2(高级模板)?
- 25. 如何更改yii2高级模板的数据库
- 26. 无法安装yii2高级模板,迁移命令
- 27. yii2高级模板:登录导致inifinite重定向循环
- 28. Yii2高级模板后端和前端在同一个域上
- 29. Ruby Prawn将METADATA添加到模板
- 30. 如何将html添加到emberjs模板?
其实在我们的联系页面,我们可以为特定的地址显示的地图,但在我的网站,我有不同的用户提供不同的位置,所以,当我想点击该特定用户I需要用地图显示他们的地址。 – Baji