Search code examples
ruby-on-railsrubydevisegmaps4railsrails-geocoder

Uncaught RangeError: Maximum call stack size exceeded


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.

this is my view:

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

the controller for dashboard view:

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

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


Solution

  • 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.