Showing multiple database-backed locations on a single Google Map, each with a clickable info window, is a matter of passing your location data from Laravel to the front end and looping it into the Maps JavaScript API's marker and InfoWindow objects.
Passing location data from the controller
public function index()
{
$stores = Store::select('name', 'address', 'latitude', 'longitude')->get();
return view('stores.map', compact('stores'));
}
The map container and script
Initializing the map and adding a marker per location
@json($stores) is what safely converts the PHP collection into a JavaScript array literal directly in the Blade view — it also handles proper escaping, avoiding the XSS risk of interpolating raw data into a block by hand.
Why a single shared InfoWindow, reused for every marker
Creating one InfoWindow instance outside the loop and reusing it (updating its content and reopening it on each marker click) is the standard pattern — creating a separate InfoWindow per marker works too, but means only ever having one truly open at a time requires manually closing the others, which the shared-instance approach avoids by construction.
Auto-fitting the map's zoom and center to all markers
const bounds = new google.maps.LatLngBounds();
stores.forEach(store => {
bounds.extend({ lat: parseFloat(store.latitude), lng: parseFloat(store.longitude) });
});
map.fitBounds(bounds);
fitBounds() automatically calculates the right zoom level and center point to fit every marker in view — more robust than hardcoding an initial zoom and center, which can leave markers outside the visible map area if the actual data doesn't match the assumption baked into those hardcoded values.
Clustering markers for a large number of locations
For a genuinely large number of markers, plotting them all individually can become visually cluttered and slow to render — the MarkerClusterer library (a separate add-on to the base Maps API) groups nearby markers into a single cluster icon at lower zoom levels, splitting apart as the user zooms in, which is worth adding once a map has more than a few dozen markers.