未捕获RangeError:超过最大调用堆栈大小 [英] Uncaught RangeError: Maximum call stack size exceeded

查看:240
本文介绍了未捕获RangeError:超过最大调用堆栈大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我试图实现一个功能,让用户在登录时搜索供应商。我使用geocoder和gmap4rails。但是,当我设置地图并尝试运行应用程序时,地图根本就不显示。

So, I'm trying to implement a feature to let user search for vendors when they log in. I'm using geocoder and gmap4rails. However, when I set up the map and try to run the app, the map doesn't show on at all.

这是我的观点:

    <%= form_tag dashboard_path, :method => :get do %>
<div class= "row">
  <p>
    <%= text_field_tag :search, params[:search], class: "col-md-4"%>
    <%= submit_tag "Search Near", class: "btn btn-info", :name => nil  %>
  </p>
  </div>
<% end %>

<div style='width: 800px;'>
  <div id="map" style='width: 9000px; height: 500px;'></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();
  handler.getMap().setZoom(15);

});

</script>

仪表板视图的控制器:

def dashboard
    if params.empty?
        gflash notice: "you cant search without a term"
        redirect_to "/"

    elsif params[:search].present?
        @vendors = Vendor.near(params[:search], 50)
        @hash = Gmaps4rails.build_markers(@vendors) do |vendor, marker|
            marker.lat vendor.latitude
            marker.lng vendor.longitude
            marker.infowindow vendor.discount_info
            marker.picture ({
            "url" => "assets/marker.png",
            "width" => 32,
            "height" => 32})
       end
    else
        @vendors = Vendor.all
        @hash = Gmaps4rails.build_markers(@vendors) do |vendor, marker|
            marker.lat vendor.latitude
            marker.lng vendor.longitude
            marker.picture ({
            "url" => "assets/marker.png",
            "width" => 32,
            "height" => 32})

        end
    end

在开发模式下,当我打开浏览器并登录网页控制台时,出现的错误是:

in the development mode when I open the browser and log in the web console said the error is:

Uncaught RangeError: Maximum call stack size exceeded

我不是确定是什么导致这个错误,Ive适当地设置地图大小。

I'm not sure what is causing this error, Ive set the map size appropriately.

推荐答案

解决问题,代码进入无限循环导致gmap崩溃的情况下,搜索参数是空的,它不知道在哪里设置标记,所以我只是设置这种情况的经度和纬度。

Solved the problem, The code went in to infinite loop cause gmap crashes on case the search parameter is empty, it didnt know where to set the marker, so I just set the longitude and latitude for that case.

这篇关于未捕获RangeError:超过最大调用堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆