Reader Stacks

Google Maps With Multiple Markers and Info Windows in Laravel

Rendering multiple locations from a database onto one map, each with its own clickable info window, is a matter of looping your data into the Maps JavaScript API's marker and InfoWindow objects.

Google Maps With Multiple Markers and Info Windows in Laravel

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