2016-05-12 111 views
0

因此,我試圖實現一項功能,讓用戶在登錄時搜索供應商。我正在使用geocoder和gmap4rails。但是,當我設置地圖並嘗試運行應用程序時,地圖根本不顯示。Uncaught RangeError:超出最大調用堆棧大小

這是我的看法:

<%= 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 

在開發模式當我打開瀏覽器,登錄到Web控制檯說,錯誤是:

Uncaught RangeError: Maximum call stack size exceeded 

我不確定是什麼導致了這個錯誤,我已經適當地設置了地圖大小。

+0

你是否在瀏覽器的Javascript控制檯中看到任何錯誤? – pgaspar

+0

@pgaspar我包含了來自Web控制檯的錯誤 – KhoaVo

回答

0

解決了這個問題,代碼進入無限循環導致gmap崩潰的情況下搜索參數爲空,它不知道在哪裏設置標記,所以我只是爲該情況設置經度和緯度。

相關問題