Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When adding circles to a gmaps4rails, I get an error that reads: TypeError: 'undefined' is not an object (evaluating 'circle.serviceObject.getBounds'

My objective is to add circles in place of markers to show the general area of the location of the each tool in the Tool model. I was able to add circles based on other answers on SO, however using the following code I get the error in the title of this question.

In my controller:

def index
  @tools = Tool.all
  @json=Tool.all.to_gmaps4rails

  @circles = Tool.all{|t| {:longitude => t.longitude, :latitude => t.latitude, :radius =>"1000" }}.to_json 
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @tools }
  end
end

In my view file:

<%= gmaps({ "markers" => {"data" => @circles}, "circles" => { "data" => @circles} }  ) %>

The JavaScript error directs me to the line 401 in the gmaps4rails.googlemaps.js file:

  this.boundsObject.extend(circle.serviceObject.getBounds().getNorthEast());

Any ideas why?

like image 766
thewheelz Avatar asked Dec 19 '12 23:12

thewheelz


1 Answers

put a break put in this.boundsObject.extend(circle.serviceObject.getBounds().getNorthEast());

and print our the circle

if i am not wrong @circle in rails is not format correctly

  @circles = Tool.map{|t| {:longitude => t.longitude, :latitude => t.latitude, :radius =>"1000" }}.to_json 

it should be map instead of all to map all the array and print out in json

like image 187
wizztjh Avatar answered Oct 20 '22 08:10

wizztjh