Not sure about what all you have in your application, but from the controller code it looks like you have model Trip with association has_many :markers
and Marker model have latitude and longitude fields.
and also you want to display all those associated markers.
Now to display the pins on google-map it requires proper activerecord-relation records
so one-way to do is
CONTROLLER:
@trips = Trip.pluck(:id)
@markers = Marker.where("trip_id in (?)", @trips)
@gmaps_options = @markers.to_gmaps4rails
VIEW:
= gmaps("markers" => { data: @gmaps_options })
Another way is:
form the json string of the all location's latitude and longitude with the help of loop and pass that string to data in view, as you have done above, because .to_gmaps4rails
does not accept array.
Hope this would help you.
Thanks.