蒸汽 / laravel-maps
为Laravel提供简单易用的地图集成。
0.8.1
2021-04-15 09:55 UTC
Requires
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- orchestra/testbench-browser-kit: ^6.0
- orchestra/testbench-dusk: ^6.0
- php-coveralls/php-coveralls: *
- phpmd/phpmd: ^2.7
- phpunit/phpunit: ^9.0
- sebastian/phpcpd: ^5.0
- symfony/thanks: ^1.2
Suggests
- geocoder-php/GeocoderLaravel: If you need to geocode addresses and don't already have marker coordinates, use this package. It provides geocoding functionality optimized for Laravel.
This package is auto-updated.
Last update: 2024-09-15 18:16:48 UTC
README
先决条件
- PHP >= 7.3
- Laravel >= 8.0
此包是 Vaporic/Phpgmaps
的延续。将包移动到更合适的命名空间是为了准备对包进行完全重写,以优化其在Laravel中的使用。
PhpGmaps
此仓库旨在保持 appitventures/phpgmaps 活跃,希望在他们再次提供仓库之前暂时填补空白,或者继续维护它,并确保它与Laravel的未来版本兼容。
安装
将仓库添加到 composer.json 中的新命名空间下
composer require vaporic/laravel-maps
在 .env
文件中添加一个包含您的 Google Maps API 密钥的环境变量
GOOGLE_MAPS_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
最后,将以下条目添加到您的 \config\services.php
配置文件中
'google' => [ 'maps' => [ 'api-key' => env('GOOGLE_MAPS_API_KEY'), ], ],
示例
以下代码将提示用户访问其地理位置,然后创建一个以用户纬度/经度为中心的地图
Route::get('/', function(){
$config = array();
$config['center'] = 'auto';
$config['onboundschanged'] = 'if (!centreGot) {
var mapCentre = map.getCenter();
marker_0.setOptions({
position: new google.maps.LatLng(mapCentre.lat(), mapCentre.lng())
});
}
centreGot = true;';
app('map')->initialize($config);
// set up the marker ready for positioning
// once we know the users location
$marker = array();
app('map')->add_marker($marker);
$map = app('map')->create_map();
echo "<html><head><script type="text/javascript">var centreGot = false;</script>".$map['js']."</head><body>".$map['html']."</body></html>";
});
更多示例
BIOINSTALL 有一个很棒的网站展示了如何使用该类做所有事情。没有必要重新发明轮子,所以 这里 是。需要注意的是,现在 $this->googlemaps
是外观 Map::
或应用变量 app('map')
。