2017-03-04 9 views
0

Ich kann nicht herausfinden, wie man das Markierungssymbol von Google Map ändert. Hier ist mein Code. Die meisten Marker sind bereits angezeigt. Ich möchte nur meinen aktuellen Standort ändern.Wie kann ich das Google Map Marker-Symbol anpassen?

-Controller

def restaurant_nearby 
     @restaurants = Restaurant.near(params[:lat], params[:lng], params[:num], params[:lang]) 
     @hash = Gmaps4rails.build_markers(@restaurants.to_hash) do |r, marker| 
         marker.lat r["lat"] 
         marker.lng r["lng"] 
         marker.infowindow render_to_string(partial: "area/infowindow", locals: { place: r }) 
         marker.json({title: r["restaurantname"]}) 
     end 

     @hash_current_pos = { 
         lat: params[:lat], 
         lng: params[:lng], 
         icon: '/here.png', 
         infowindow: render_to_string(partial: "area/infowindow_current_pos"), 
         title: "You are here" 
     } 

     @hash = @hash.push(@hash_current_pos) 

     content = render_to_string(:partial => 'area/restaurant_map', locals: {hash: @hash}) 
     render json: {html: content}, status: :ok 
    end 

Hier Skript Blickwinkel. Bereich/_restaurant_map.html.slim

javascript: 
    jQuery(function(){ 

     mapStyle = [[{"featureType":"administrative.country","elementType":"geometry.fill","stylers":[{"saturation":"-35"}]}]]; 

     handler = Gmaps.build('Google'); 
     handler.buildMap({ provider: {styles: mapStyle}, internal: {id: 'map'}}, function(){ 
     markers = handler.addMarkers(#{raw hash.to_json}); 
     handler.bounds.extendWith(markers); 
     handler.fitMapToBounds(); 
     handler.getMap().setZoom(15); 
     }); 
}); 

/! Le HTML5 shim, for IE6-8 support of HTML elements 
/[if lt IE 9] 
    = javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js" 

ich alle Ratschläge schätzen würde.

Antwort

-1

Wenn Sie nur die Google-Symbol anpassen möchten, können Sie einstellen, ein size und color

Andernfalls markers=icon:URLofIcon|markerLocation

URLofIcon die URL des Symbols ist, möchten Sie verwenden möchten, die URL-kodiert sein sollte (mit einem Verkürzungsdienst, der wahrscheinlich URL für Sie kodieren wird und den Code viel schöner aussehen lässt)

+0

Ihre Antwort sollte besser spezifiziert werden, d. H. Wo die Lösung, einige Codebeispiele .. – Massimo

0

Schließlich habe ich ausgearbeitet. So was.

@hash_current_pos = { 
         lat: params[:lat], 
         lng: params[:lng], 
         picture: {url: '/here.png', width: 140, height: 180}, 
         infowindow: render_to_string(partial: "area/infowindow_current_pos"), 
         title: "You are here" 
     } 

Anerkannt alles trägt dazu bei!

Verwandte Themen