apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

How to add multiple arrays markers on the map #410

Closed galievruslan closed 10 years ago

galievruslan commented 10 years ago

Prompt how can I add to the existing array of markers more markers. My code in the controller :

    @markers = @last_location.to_gmaps4rails do | location, marker |
        marker.infowindow render_to_string (: partial => "/ reports / location",: locals => {: object => location})
        marker.picture ({: picture => '/ assets / start.png',: width => 24 ,: height => 24 ,: marker_anchor => [ 12, 24 ] } )
        marker.title location.timestamp.to_s
    end
    if params [: with_route_points]
      route = Route.find_by_date_and_manager_id (params [: q] [: timestamp_gt], params [: q] [: user_manager_id_eq])
        if route   
          @route_point_locations = route.shipping_addresses.to_gmaps4rails do | location, marker |   
          marker.infowindow render_to_string (: partial => "/ reports / shipping_address_location",: locals => {: object => location})   
          marker.title location.name.to_s   
        end   
        # @Markers = @markers + @route_point_locations   
      end   
    end   

My code is in view:

<% = Gmaps ({"markers" => {"data" => @markers}, "polylines" => {"data" => @polyline, "options" => {"strokeColor" => "# 0088cc" } } } )%>

I want to move the point markers and _route_pointlocations on one map. But no matter how I tried it does not work, because is not an array, and string. I have the latest version of the "crutch" to remove it in one line with a '[' and the other ']'

apneadiving commented 10 years ago

this was not convenient in v1, it has changed in v2.

You can do:

@Markers = JSON.parse(@markers) + JSON.parse(@route_point_locations)

next time please ask on stackoverflow