genealabs / laravel-maps
Eay - peasy map integration for Laravel.
Installs: 29 324
Dependents: 0
Suggesters: 0
Security: 0
Stars: 81
Watchers: 9
Forks: 29
Open Issues: 7
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
Prerequisites
- PHP >= 7.3
- Laravel >= 8.0
This package is the continuation of GeneaLabs/Phpgmaps
. The move to the more appropriately-named package namespace is in preparation for a complete rewrite of the package, optimizing it for Laravel.
PhpGmaps
This repo aims to keep appitventures/phpgmaps alive, hopefully filling in temporarily until they make their repo available again, or else continuing its maintenance going forward and keeping it working with future versions of Laravel.
Installation
Add the repo to composer.json under this new namespace:
composer require genealabs/laravel-maps
Add an environment variable with your Google Maps API Key in your .env
file:
GOOGLE_MAPS_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Lastly, add the following entry to your \config\services.php
config file:
'google' => [ 'maps' => [ 'api-key' => env('GOOGLE_MAPS_API_KEY'), ], ],
Example
The following code will prompt the user for access to their geolocation and then creates a map centered on their lat/lng
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>";
});
More Examples
BIOINSTALL has a great website showing how to do all the things with the class. No reason to reinvent the wheel, so here it is. The only thing to note is that $this->googlemaps
is now either the facade Map::
or the app variable app('map')
.