genealabs / laravel-maps
为Laravel提供的简单地图集成。
0.9.0
2023-10-20 12:46 UTC
Requires
- illuminate/support: ^8.0|^9.0|^10.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-20 14:51:29 UTC
README
先决条件
- PHP >= 7.3
- Laravel >= 8.0
此包是 GeneaLabs/Phpgmaps
的延续。迁移到更合适的包命名空间是为了准备对包进行彻底重写,优化其在 Laravel 上的性能。
PhpGmaps
此仓库旨在保持 appitventures/phpgmaps 项目的活跃状态,希望能暂时填补空缺,直到他们再次提供仓库,或者继续维护并使其与 Laravel 的未来版本兼容。
安装
将仓库添加到 composer.json 中的新命名空间下
composer require genealabs/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')
。