gmaps4rails 2 でポリラインを使用しようとしていますが、エラーの原因がわかりません...
ポリラインをハードコーディングすると、マップが期待どおりに表示されます。ただし、コントローラーからデータを取得すると、「Uncaught TypeError: number is not a function」が表示されます
ハードコーディングされたポリラインを使用した次のコードが機能します
見る
<script>
$('#myModal2').on('shown.bs.modal', function (e) {
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map2'}}, function(){
polyline = [{"lat":49.9574400,"lng":-123.1201800}, {"lat":49.9465300,"lng":-123.0553700},{"lat":49.9598300,"lng":-123.0475400},{"lat":49.9750500,"lng":-123.0427700}];
handler.addPolyline(polyline);
handler.bounds.extend(polyline[0]);
handler.bounds.extend(polyline[ polyline.length - 1]);
handler.fitMapToBounds();
handler.getMap().setZoom(12);
});
});
</script>
しかし、これはそうではありません
<script>
$('#myModal2').on('shown.bs.modal', function (e) {
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map2'}}, function(){
polyline = <%=raw @hashroute.to_json %>;
handler.addPolyline(polyline);
handler.bounds.extend(polyline[0]);
handler.bounds.extend(polyline[ polyline.length - 1]);
handler.fitMapToBounds();
handler.getMap().setZoom(12);
});
});
</script>
コントローラ
def show
@hashroute =[]
@list.routes.each do |route|
@hashroute << { :lat => route.from_lat, :long => route.from_long}
@hashroute << { :lat => route.to_lat, :long => route.to_long}
end
respond_to do |format|
format.html {render :show}
format.json { head :ok}
end
end
@hashroute.to_json は適切に入力され、コンソールのポリラインはハードコードされたバージョンと同じように見えます
動作するコンソールコード
うまくいかないとき
何か案が?