我找不出如何更改Google地图的标记图标。 这是我的代码。大部分标记已经显示。我只想更改我目前的位置。如何自定义Google地图标记图标?
控制器
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
这里是视图脚本。 面积/ _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"
我会很感激的任何建议。
您的答案应该更好地指定,即放置解决方案的位置,一些代码示例。 – Massimo