Closed gabebw closed 10 years ago
Could you copy paste the generated js ?
Sent from my iPad
On 24 Jul 2014, at 23:22, Gabe Berke-Williams notifications@github.com wrote:
Hi,
In my code, the Chrome debugger is telling me that this.clusterer is null in Handler.prototype.addMarker. I'm calling handler.addMarkers(<%=raw @hash.to_json %>) and the hash is correctly being generated, but it crashes on that. Any ideas?
— Reply to this email directly or view it on GitHub.
I think this is what you want. It's at the bottom of my view:
$(function(){
markers = window.handler.addMarkers([{"lat":42.3584308,"lng":-71.0597732},{"lat":40.7127837,"lng":-74.0059413},{"lat":42.2286954,"lng":-71.5225646},{"lat":42.3736158,"lng":-71.1097335}]);
});
And here's the contents of my file, autoloaded in application.js
:
$(function(){
window.handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers([
{
"lat": "42.3584308",
"lng": "-71.0636",
"picture": {
"url": "http://www.googlemapsmarkers.com/v1/009900/",
"width": 36,
"height": 36
},
"infowindow": "hello!"
}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
handler.getMap().setZoom(10);
});
});
The exact error I get is:
Uncaught TypeError: Cannot read property 'addMarker' of undefined (handler.js line 38)
It's trying to call this.clusterer.addMarker
.
I guess application.js
is called after your $()
line.
Order matters in js
That makes sense. Is there any way to guarantee that one of the handlers happens after the other one? I assume that jQuery runs each event handler in the event that they're added.
You should create a js function which creates the map and pass it your callback
Thank you! That worked.
Can you give an example on how to do that? I've been struggling for a while Thanks a lot!
@mrpadi It's been a while since I looked at the code, but if you link to a gist of your JS code, I can take a look.
Hi,
In my code, the Chrome debugger is telling me that
this.clusterer
is null inHandler.prototype.addMarker
. I'm callinghandler.addMarkers(<%=raw @hash.to_json %>)
and the hash is correctly being generated, but it crashes on that. Any ideas?