apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

maxZoom undefined in markerclusterer_compiled.js #97

Closed hameno closed 13 years ago

hameno commented 13 years ago

Hi I'm trying to display some markers but since a few days I'm getting this error and no markers are shown:

markerclusterer_compiled.js:1  Uncaught TypeError: Cannot read property 'maxZoom' of undefined

My gem version: gmaps4rails (1.1.5)

apneadiving commented 13 years ago

Hi,

That's annoying.. I'll try today...

What's your code please?

hameno commented 13 years ago

I'm currently on the way to work. Code is nothing special, will post it when I'm at work.

eetteri commented 13 years ago

Same problem started to occur to me too suddenly. Problem is in the google utility library markerclusterer.js. I'm getting the error below when creating the map

markerclusterer.js:90TypeError: 'undefined' is not an object (evaluating 'that.map_.mapTypes[that.map_.getMapTypeId()].maxZoom')

and the related js

// Add the map event listeners
  var that = this;
  google.maps.event.addListener(this.map_, 'zoom_changed', function() {
    var maxZoom = that.map_.mapTypes[that.map_.getMapTypeId()].maxZoom;
    var zoom = that.map_.getZoom();
    if (zoom < 0 || zoom > maxZoom) {
      return;
    }

While looking at this, I noticed that google utility library has markerclustererplus, which is backward compatible with the version 1.0 and when I tried it, it solved the above problem but also another problem I was having when using gmap4rails replaceMarkers() call on AJAX updates. Any change to move to that library?

hameno commented 13 years ago

So here's the code:

<%= gmaps({
    :map_options => { :detect_location => false, :center_on_user => false, :zoom => 6},
    :markers => { :data => @json },
    :polylines => { :data => @line_json , :options => { :strokeColor => "#000" }},
    :circles    => { :data => @circles_json }
    }) %>

Controller:

@routes = current_user.routes
@route = @routes.find(params[:id])
routepoints = @route.route_points.order("fixed_at ASC")
points = Array.new
lines = Array.new
circles = Array.new
routepoints.each do |rp|
  points << rp
  circles << { "lng" => rp.longitude, "lat" => rp.latitude, "radius" => rp.accuracy }
end
0.upto(points.length-2) do |i|
  line = Array.new
  line << {"lat" => points[i].latitude, "lng" => points[i].longitude}
  line << {"lat" => points[i+1].latitude, "lng" => points[i+1].longitude}
  lines << line
end

logger.info points
@json = points.to_gmaps4rails
@line_json = lines.to_json
@circles_json = circles.to_json

(It's certainly not very clean or good code - just starting with ruby and rails)

eetteri commented 13 years ago

Well, the problem is definitely on googles utility library end, all their examples are broken also

apneadiving commented 13 years ago

@eetteri:

Ok sounds like a problem unrelated to the gem then.

I'll move to markerClustererPlus in a release tonight.

Thanks for the tip

hdkmraf commented 13 years ago

Seems like this is related to the problem: http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/703b11a00d964c4e

"The function hasn't been exported for compiling. I can export it if needed but you can set the maxZoom in the options when you create the object:

var mymarkerclusterer = new MarkerClusterer(map, null, { maxZoom: 11

}); "

hdkmraf commented 13 years ago

Yep, the problem was markerClusterer

Replaced:

<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.js"></script>

for:

<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.1/src/markerclusterer.js"></script>

in app/views/gmaps4rails/_gmaps4rails.html.erb

and it is rolling again!

Thanks!

apneadiving commented 13 years ago

Few things here:

  1. I'm impressed by the reactivity of you all: answer came really quickly. Big thanks :)
  2. No bug for me but since the other script works fine too, I'll replace the former.

Cheers!

eetteri commented 13 years ago

Yeah, you are right, the original 1.0 library seems to be working again. There definitely was something funky going on with that library earlier today as seen in Google Maps email group thread from this day

Thanks for the library upgrade anyway, since that solves another problem I just recently pumped into and had not been able to solve.