yappabe/google-map-form-type-bundle
A Symfony bundle that adds a Google Maps form type for visually selecting locations. Embed an interactive map in forms so users can pick a point and submit latitude/longitude coordinates without manual entry, simplifying location-based form inputs.
This is a Symfony bundle, not a Laravel package. The first thing to understand is that yappabe/google-map-form-type-bundle integrates with Symfony's Form component and Twig. You cannot composer require it into a Laravel app and expect a working form field — there is no service provider, no Blade view, and it depends on symfony/form and symfony/twig-bridge classes. For a Laravel codebase, the realistic path is to read the source and reimplement the small piece you need, or fork the Twig/JS into a Blade component. The whole payload is essentially one form type plus a Google Maps JS snippet, so porting is a few hours of work, not a migration project.
If you are actually on Symfony (or evaluating for one), the minimal steps are:
composer require yappabe/google-map-form-type-bundle (pin the 2018 release; it is archived, so no bugfixes).new Oh\GoogleMapFormTypeBundle\OhGoogleMapFormTypeBundle() in config/bundles.php / AppKernel.use Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType;
$builder
->add('latitude', HiddenType::class)
->add('longitude', HiddenType::class)
->add('map', GoogleMapType::class, [
'lat' => $entity->getLatitude() ?: 45.4642,
'lng' => $entity->getLongitude() ?: 9.1900,
'zoom' => 12,
'width' => '100%',
'height'=> '400px',
]);
Where to look first: the form type class (options and data mapping) and the bundled Twig template (the JS that pushes marker coordinates into the hidden fields). The README is thin; the template is the real documentation.
First use case: an entity with latitude/longitude columns (e.g. a store, venue, or delivery address) where an admin drags a pin instead of typing coordinates.
Store coordinates as two scalars, not a single field. The type is a compound widget that writes into lat/lng inputs. Keep latitude/longitude as nullable decimal(10,7) columns and let the form type populate hidden inputs; map them in the controller with a small data transformer or a setCoordinates() mutator.
Compose with an address field. In practice the map is secondary: users type an address, you geocode it (server-side via the Geocoding API or client-side), then set the hidden lat/lng and let the map widget initialize at those values. Pattern:
$builder
->add('address', TextType::class)
->add('latitude', HiddenType::class)
->add('longitude', HiddenType::class)
->add('map', GoogleMapType::class, ['lat' => ..., 'lng' => ...]);
Then a small JS hook moves the marker after geocoding and dispatches change on the hidden inputs so Symfony's form sees the values.
Use it as the canonical "location picker" type. Wrap it in your own LocationPickerType so every entity form gets consistent defaults (zoom, height, map type, API key) instead of repeating a dozen options. That wrapper is also where you attach a PRE_SUBMIT listener to reject null/invalid coordinates.
Form theme override. The bundle registers a Twig form theme; if your design system expects specific markup, override the block in templates/form/ rather than editing vendor files. That template is your extension point for adding an "address search" box or a "use my location" button.
For Laravel (the likely real-world path): copy the concept into a Blade component.
{{-- resources/views/components/map-picker.blade.php --}}
<div x-data="mapPicker(@js($lat), @js($lng))" wire:ignore>
<div x-ref="map" style="height:400px"></div>
<input type="hidden" name="latitude" x-model="lat">
<input type="hidden" name="longitude" x-model="lng">
</div>
With validation rules ['required','numeric','between:-90,90'] / between:-180,180, and a controller that writes the validated pair to the model. This gives you the same UX with none of the abandoned-bundle risk.
if (!window.google?.maps).null from an untouched map is a common source of 0,0 ("Null Island") records — add a PRE_SUBMIT/request validator that rejects lat === null || lng === null.script-src https://maps.googleapis.com and often img-src https://maps.gstatic.com data:. On HTTPS-only pages an internally hardcoded http:// marker icon will silently fail.data-* attribute. Don't hardcode it in the vendor template; put it in .env/parameters.200 from maps.googleapis.com/maps/api/js; check the console for RefererNotAllowedMapError / ApiNotActivatedMapError; inspect the hidden inputs in the DOM after dragging — if they don't update, the Twig theme's JS didn't attach (usually because the map container rendered before the script loaded).configureOptions (defaults for zoom/type/dimensions), the Twig block (markup + JS bootstrap), and a data transformer if you want to map a value object (Coordinates) instead of two scalar columns.How can I help you explore Laravel packages today?