如何为位置添加半径和颜色

how to add radius and color for location

我是 gmap4rails 的新手 gem 我在 wiki 上看到这个 https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Circles

但是当我用我的代码尝试时 我把这个

  def index
    @ads = Ad.all
    @hash = Gmaps4rails.build_markers(@ads) do |ads, marker|
  marker.lat ads.latitude
  marker.lng ads.longitude
  marker.infowindow ads.name
  end
@circles_json = '[
 {"lng": -122.214897, "lat": 37.772323, "radius": 1000000},
 //you can add whatever customization within the hash
 {"lng": 122.214897, "lat": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"}
]'
  end

<script type="text/javascript">
  handler = Gmaps.build('Google');
  handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
   markers = handler.addMarkers(<%=raw @hash.to_json %>);
   circle = handler.addMarkers(<%= gmaps({"circles"=> { "data" => @circles_json }})%>);
   handler.bounds.extendWith(markers);
   handler.fitMapToBounds();

 });
</script>

和文件 application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require underscore
//= require gmaps/google
//= require_tree .

遇到了这个问题 enter image description here

您是否在 dom 中插入了 google 脚本?

您是否在 application.js 中添加了以下行?

//= require underscore
//= require gmaps/google

尝试

<script type="text/javascript">
    handler = Gmaps.build('Google');
    handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
        markers = handler.addMarkers(<%=raw @hash.to_json %>);

        var circles = handler.addCircles(
            [
                {"lng": 122.214897, "lat": 37.772323, "radius": 1000000, "strokeColor": "#FF0000"}
            ]
        );

        handler.bounds.extendWith(markers);
        handler.bounds.extendWith(circles);
        handler.fitMapToBounds();

    });

</script>