[size=medium][color=blue]原文地址:[/color] [/size][[url]http://ywencn.iteye.com/blog/423731[/url] [color=blue]将GoogleMap轻松应用到Rails中[/color]
[color=green]
我的cartographer插件是在这里下载的:http://github.com/joshuamiller/cartographer
照着上面的步骤在rails中做了下,在数据库里添加数据[address = 苏州 lat = 31.2977790000 lng = 120.5855860000]
发布的时候报:undefined method `[]' for true:TrueClass
在index页面上<%= @map.to_html(true) %>去掉(true),又报uninitialized class variable @@window_onload in Cartographer::Gmap
在gmap.rb文件中加入@@window_onload = "",这次可以了,但地图上显示的地区不是苏州
[/color]
,我控制器了改了下代码,
这次OK了
后来看了web开发大全.rubyonrails地图服务中的源代码加了个新建地区功能,
web开发大全.rubyonrails地图服务中的cartographer插件是不用改的
项目demo我上传了
[color=green]
我的cartographer插件是在这里下载的:http://github.com/joshuamiller/cartographer
照着上面的步骤在rails中做了下,在数据库里添加数据[address = 苏州 lat = 31.2977790000 lng = 120.5855860000]
发布的时候报:undefined method `[]' for true:TrueClass
在index页面上<%= @map.to_html(true) %>去掉(true),又报uninitialized class variable @@window_onload in Cartographer::Gmap
在gmap.rb文件中加入@@window_onload = "",这次可以了,但地图上显示的地区不是苏州
[/color]
,我控制器了改了下代码,
def index
@locations = Location.find(:last)
@map = Cartographer::Gmap.new("gmaps")
@map.controls = [ :large, :scale ]
@map.debug = true
@map.center = [@locations.lat, @locations.lng]
# @locations.each do |location|
# @map.markers << Cartographer::Gmarker.new(:name => "location_" + location.id.to_s, :position => [location.lat.to_s, location.lng.to_s], :info_window => location.description, :map => @map )
#
# end
end
这次OK了
后来看了web开发大全.rubyonrails地图服务中的源代码加了个新建地区功能,
web开发大全.rubyonrails地图服务中的cartographer插件是不用改的
项目demo我上传了
本文介绍了如何使用cartographer插件将Google Maps集成到Rails应用程序中,并解决了在集成过程中遇到的问题,如方法未定义错误和初始化问题。此外还分享了如何在地图上标记位置的具体实现。
1898

被折叠的 条评论
为什么被折叠?



