puwnz/google-maps-lib
puwnz/google-maps-lib is a PHP library for adding Google Maps capabilities to your project, offering a straightforward wrapper for common mapping and location-based API tasks. It helps reduce boilerplate when integrating maps into PHP applications.
Install via Composer (it is a plain PHP library, not a Laravel package, so there is no service provider to discover):
composer require puwnz/google-maps-lib
Confirm your project satisfies the PHP 7.3+ requirement — if you are on an older runtime the constraint will resolve to nothing or fail.
Read the README first, then the source. With a single-star package the README is the spec. After that, list vendor/puwnz/google-maps-lib/src to see the actual classes. The library is small, so you should be able to read the whole namespace in one sitting before relying on it — this is the fastest way to learn the real method signatures rather than guessing from docs.
Gather your Google Maps API key. The library is a thin wrapper that generates the map markup/JS; it does not magically get you a key. Enable the Maps JavaScript API in Google Cloud Console and restrict the key by HTTP referrer for the browser.
First use case: render a map with a center point and one marker in a Blade view.
// app/Http/Controllers/MapController.php
public function show()
{
$map = new \Puwnz\GoogleMapsLib\...\GoogleMap(config('services.google.maps_key'));
$map->setCenter(51.5074, -0.1278);
$map->addMarker(51.5074, -0.1278, 'London');
return view('map', ['map' => $map]);
}
{{-- resources/views/map.blade.php --}}
{!! $map->render() !!}
Verify the exact namespace and method names against src/ — the README is the only reliable reference. Once one marker renders, you have validated install, autoload, API key, and output path in a single step.
{!! $map->render() !!} it. Keep the map setup out of Blade so it stays testable.MapService (or GoogleMapFactory) in app/Services that owns the package. When the package is abandoned (see Gotchas) you replace one file instead of grepping the codebase.config/services.php under a google.maps_key entry reading env('GOOGLE_MAPS_KEY'). Never hard-code it in a controller or pass it from a request.foreach (Venue::all() as $venue) {
$map->addMarker($venue->lat, $venue->lng, $venue->name);
}
render() (contains the center coordinates and marker count) or stub the service. Snapshot the rendered output is enough for regression coverage.ServiceProvider, no Facade, no published config. You wire it manually. Do not add it to config/app.php providers — it will error.render() emits is visible to visitors. Referrer restrictions and API restrictions in Cloud Console are your only protection; a server-side proxy is overkill for a JS-API wrapper but you cannot hide the key.~ constraint in composer.json and commit composer.lock. Do not composer update this package blindly.{} string offsets, dynamic properties). Add a compatibility test.RefererNotAllowedMapError, InvalidKeyMapError). These are Google errors, not package errors — do not waste time in the library source.json_encode or e() the values yourself before passing them in.googlemaps/markerclusterer, a Blade component that emits the JS API directly, or another maintained wrapper is a single-file change.How can I help you explore Laravel packages today?