[英]Google maps for Rails: after map load callback
How can I add a callback function to the infowindow in Gmaps for Rails? 如何在Gmaps for Rails的信息窗口中添加回调函数? I need to write an Ajax/JSON function for buttons inside that window.
我需要为该窗口内的按钮编写一个Ajax / JSON函数。
Searching hasn't gotten me very far. 搜索还不算太远。 Any help?
有什么帮助吗?
<script type='text/javascript'>
handler = Gmaps.build('Google');
handler.buildMap({
provider: {
mapTypeId: google.maps.MapTypeId.SATELLITE
},
internal: { id: 'map' }
},
function(){
markers = handler.addMarkers(<%= raw @map_hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
// trying to add this function
google.maps.event.addListenerOnce(handler.map, 'idle', function() {
console.log('map loaded');
$('.survey-response').click(function() {
var id = $(this).attr('data-id');
var response = $(this).attr('data-response');
console.log(id + ' ' + response);
$.getJSON('/potentials/' + id + '/' + response, function (data) {
console.log(data);
})
})
})
});
</script>
Removing the callback from above (after the comment) and using this code: 从上面删除回调(在注释之后)并使用以下代码:
google.maps.event.addListener(Gmaps.map, "click", function() {
alert("You clicked the map.");
});
Returns this error: 返回此错误:
Cannot read property '__e3_' of undefined
Thanks. 谢谢。
You should create your own builder to handle the infowindows as explained there . 您应该创建自己的构建来处理信息窗口的解释存在 。
This way you can bind your js events as you need. 这样,您可以根据需要绑定js事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.