Gmaps4rails标记未显示

时间:2015-07-19 10:50:50

标签: ruby-on-rails gmaps4rails

在没有使用gmaps4rails显示的标记时出现问题,请浏览教程视频,仍然没有任何乐趣。我已确认地理编码器工作正常。

@shops controller

def index
@shops = Shop.all
@hash = Gmaps4rails.build_markers(@shops) do |shop, marker|
  marker.lat shop.latitude
  marker.lng shop.longitude
  marker.title shop.description
end

查看

<div style='width: 800px;'>
   <div id="map" style='width: 800px; height: 400px;'></div>
</div>   
    <script type="text/javascript">
      handler = Gmaps.build('Google');
        handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
          markers = handler.addMarkers(<%=raw @hash.to_json %>);
          handler.bounds.extendWith(markers);
          handler.fitMapToBounds();
        });
    </script>

1 个答案:

答案 0 :(得分:1)

我不是百分百肯定,但我认为<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:name="com.demo.mytoolbar.MainFragment" android:id="@+id/fragment_new_park_item" android:layout_width="match_parent" android:layout_height="match_parent"> </fragment> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" /> </android.support.design.widget.AppBarLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/action_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="16dp" android:src="@android:drawable/ic_menu_add" /> </android.support.design.widget.CoordinatorLayout> 可能是问题 - 你试过marker.title吗?

还可以尝试:marker.infowindow

图片的标题说明: handler.addMarkers(#{raw(@hash)})不是变量的好名称,为什么不@hash? 我也会在控制器中调用@markers - 我会将其留在视图之外:只需在```index``的末尾添加.to_json

我希望有所帮助!

相关问题