fungio/google-map
fungio/google-map is a PHP package for integrating Google Maps into Laravel/PHP applications, offering utilities to simplify map setup, markers, and location-based features.
Install and confirm the package actually loads.
composer require fungio/google-map
Two things to verify before writing any code:
fungio/fungio-google-map; check packagist.org for the published vendor/package name — if it isn't published, add a VCS repository entry to composer.json instead.extra.laravel in composer.json. Assume no auto-discovery: if src/ contains a *ServiceProvider, register it manually in config/app.php (providers and, if present, aliases). If it doesn't, you just instantiate the classes directly.Where to look first: the README example block, then src/. The surface area is small — expect a map class, a marker/lat-lng value object, and a render method that returns a <script> string for the Google Maps JS API v3. Read the render method before anything else; it tells you exactly what HTML/JS you're responsible for loading around it.
First use case — a contact page with one pin. Build the map in a controller, not in Blade:
// app/Http/Controllers/ContactController.php
public function show()
{
$map = new Map(); // verify class name in src/
$map->setCenter(55.75, 37.61); // lat, lng
$map->setZoom(14);
$map->addMarker(55.75, 37.61, 'Our office');
return view('contact', ['mapHtml' => $map->render()]);
}
{{-- resources/views/contact.blade.php --}}
<div id="map" style="height:400px"></div>
{!! $mapHtml !!}
The double-brace vs. {!! !!} distinction here is not cosmetic — see Gotchas.
Wrap it in your own factory. With 0 stars and 0 dependents, treat this package as a disposable dependency. Put a MapFactory or a small GoogleMap service behind a container binding so a future swap to @googlemaps/js-api-loader (or plain hand-written JS) touches one file:
// app/Services/MapFactory.php
class MapFactory
{
public function make(float $lat, float $lng, int $zoom = 14)
{
$map = new \Fungio\GoogleMap\Map();
$map->setCenter($lat, $lng);
$map->setZoom($zoom);
return $map;
}
}
Pulling markers from Eloquent. This is the pattern you'll use most:
$map = app(MapFactory::class)->make(config('services.maps.center_lat'), config('services.maps.center_lng'));
Location::where('active', true)->each(function ($loc) use ($map) {
$map->addMarker($loc->lat, $loc->lng, e($loc->name)); // escape user data here, not in Blade
});
Keep the API key in config, not in the map object. The package predates modern key handling, so you'll likely inject the key yourself when you emit the <script src="https://maps.googleapis.com/maps/api/js?key=..."> tag in your layout. Store it in config/services.php and reference config('services.maps.key') — never hardcode it in a Blade partial.
Multiple maps per page. Because the package emits raw JS, you'll get colliding initMap-style globals. Give each map a unique DOM id and a unique init function name, or append the rendered output inside an IIFE. A Blade component that takes a $mapId argument is the cleanest fix:
<x-google-map :html="$mapHtml" id="contact-map" />
Testing is cheap — assert on the string. No network calls are made; the package just builds text. So test the rendered output:
$html = app(MapFactory::class)->make(1.0, 2.0)->render();
$this->assertStringContainsString('new google.maps.Map', $html);
$this->assertStringContainsString('1', $html); // center coords present
That's the extent of what's worth testing. Don't try to assert marker visuals — that's Google's job.
Inertia / Livewire. This package produces a string of <script> markup that expects to run on page load. In a SPA-ish context, either render the map client-side with the official loader and skip this package entirely, or inject the script via x-html and manually trigger the init. For Livewire, wire:ignore on the map container is mandatory or the map gets destroyed on every re-render.
${var} string interpolation (deprecated in 8.2) and each()/create_function (removed in 8.0). Before adopting, grep -rn 'create_function\|each(' vendor/fungio/ and run the test suite on your PHP version. If it errors, fork it — you will not get an upstream fix at 0 stars.{!! $mapHtml !!} is required, but any marker label or info-window content you passed in is now executable markup. Escape at the point of addMarker(), not in the template.key= parameter is actually on the Maps JS request.<script src=".../js"> and your layout already loads it, you'll get "You have included the Google Maps JavaScript API multiple times." Decide on one owner of that tag — ideally your layout, with async defer and a callback — and strip or ignore the package's.composer update will silently revert it.How can I help you explore Laravel packages today?