5
A
回答
10
这里是我做到了,我只能更换
在您看来(index.html.erb):
<%= gmaps({ "map_options" => { "zoom" => 15,
"auto_adjust" => false,
"detect_location" => true,
"center_on_user" => true }}, false, true) %>
用户完成平移或缩放,如果您需要不同的行为,然后使用不同的事件侦听器后的标记3210
在视图的底部添加:
<script type="text/javascript" charset="utf-8">
function gmaps4rails_callback() {
google.maps.event.addListener(Gmaps4Rails.map, 'idle', function() {
var bounds = Gmaps4Rails.map.getBounds();
drawItems(bounds);
});
}
</script>
在application.js中(使用jQuery):
function drawItems(theBounds) {
var url = '/venues.json/?sw_y=' + theBounds.getSouthWest().lng() +
'&sw_x=' + theBounds.getSouthWest().lat() +
'&ne_y=' + theBounds.getNorthEast().lng() +
'&ne_x=' + theBounds.getNorthEast().lat();
$.get(url, function(newItemData) {
Gmaps4Rails.replace_markers(newItemData);
});
}
venues_controller#指数:
def index
# Only pull venues within the visible bounds of the map
if (params[:sw_y] && params[:sw_x] && params[:ne_y] && params[:ne_x])
bounds = [ [params[:sw_x].to_f, params[:sw_y].to_f],
[params[:ne_x].to_f, params[:ne_y].to_f] ]
@venues_within_bounds = Venue.within_bounds(bounds)
else
@venues_within_bounds = Venue.all
end
respond_to do |format|
format.html # index.html.erb
format.json {
@data = @venues_within_bounds.collect {|v| {
:longitude => v.longitude,
:latitude => v.latitude,
:picture => v.marker_picture,
:title => v.marker_title
}
render :json => @data
}
end
end
Venue.rb模型(使用mongodb和mongoid):
def self.within_bounds(bounds)
self.where(:location.within => {"$box" => bounds })
end
2
哇,你真的为宝石:)
这里很多反馈我如何使用它:
只加载有用的标记,我使用geokit-rails3它们进行过滤及以下范围:
Location.in_bounds([@south_west_point, @north_east_point], :origin => @somewhere)
当变焦或跨度,我只能依靠其拧紧过程聚类
配置,地图中心和原变焦,看到here
你应该编写自己的方法来获得当前的边界,可以考虑拉:)
相关问题
- 1. 谷歌地图坏gmaps4rails
- 2. 带有gmaps4rails的谷歌地图中的不同标记
- 3. Rails,谷歌地图的rails(gmaps4rails) - 标记列表
- 4. 在谷歌地图中添加标记谷歌地图反应
- 5. 如何动态更改谷歌地图标记后添加
- 6. 动态添加InfoWindows和标记谷歌地图V3
- 7. 谷歌地图:动态标记定位地图
- 8. 如何拖动标记添加到谷歌地图使用jQuery
- 9. 谷歌地图上的动态标记图标
- 10. 动态改变融合表谷歌地图的标记图标?
- 11. 点击标记谷歌地图API和更改页面使用gmaps4rails
- 12. 动态加载的Javascript谷歌地图API:点击标记弹出
- 13. 如何在Android谷歌地图中为当前位置动态加载标记?
- 14. 谷歌地图:无法添加标记
- 15. 添加标记 - 谷歌地图API V3
- 16. 谷歌地图添加标记与AJAX
- 17. 在谷歌地图上添加标记
- 18. 添加标记GMaps(谷歌地图)
- 19. 添加ID到谷歌地图标记
- 20. 谷歌地图标记infowindow
- 21. android谷歌地图标记
- 22. 谷歌地图标记DROP
- 23. 谷歌地图标记
- 24. 标记谷歌地图
- 25. 谷歌地图 - 多标记
- 26. 谷歌地图标记
- 27. 标记在谷歌地图
- 28. 谷歌地图API标记
- 29. 谷歌地图 - 多标记
- 30. 谷歌地图:getSelected标记
这是一个很好的答案,+1 – apneadiving 2011-05-24 22:32:10