Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FounderStartup's avatar

how to show multiple locations on google map ?

I need to show property listings in google map. Presently my code is for showing listings but I have no idea how to display the coordinates of the database locations on the google map. I have some idea of the required controller :

my controller :

    public function ListingsGoogle(){

            $markers = Listing::select('autocomplete','latitude','longitude')->get();

            $markers = $markers->map(function ($item, $key){
                return [$item->autocomplete, $item->latitude, $item->longitude];
            });

            $listing = Listing::get();
            $listingscount = Listing::count();

    	return view('frontend.listings_google', compact('listingscount','listing','markers'));
    }

The javascript file provided by the template designer has the following section for showing locations :

var locations = [
 
  // Locations
  [ locationData('URL','images/company-logo-01.png',"Company Name",'Job Name', 'verified'), 37.788181, -122.461270, 5, ''],
  [ locationData('URL','images/company-logo-02.png',"Company Name",'Job Name', 'not-verified'), 37.788181, -122.461270, 5, ''],
 
];

What will be the javascript code for displaying the multiple locations ? Is the controller ok ?

0 likes
3 replies
Snapey's avatar

You need to iterate over the markers in a blade foreach loop and then output in the same format as your example.

If you arrange the array with just the right keys and values, you might just be able to do

var locations = @json($markers)

but it depends what Laravel version you have to know if this is available to you

1 like

Please or to participate in this conversation.