【问题标题】:gmaps4rails isn't displaying given coordinatesgmaps4rails 不显示给定坐标
【发布时间】:2012-10-23 06:47:52
【问题描述】:

我已经让整个地图正确显示,没有任何问题。但是,地图总是在0,0 的坐标处加载。我知道我也正确传递了经度和纬度。

这是gmaps4rails 方法接收的打印json:

[{"lat":40.7142,"lng":74.0064}]

以下也是各个生产领域使用的代码...

查看

<%= @maps %>
<%= gmaps4rails(@maps) %>

型号

acts_as_gmappable :process_geocoding => false, :lat => :lat, :lng => :lng

def lat
  40.7142
end

def lng
  74.0064
end

控制器

@maps = Event.find(params[:id]).to_gmaps4rails

正如您将在我的模型中看到的那样,我已决定明确传递纬度和经度。我的数据库设置确实包含latitudelongitude 列,但是,我目前正在处理测试数据,不能期望得到可靠的结果。在此之前,我将使用纽约市的坐标。

这是输出的 Javascript:

Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
Gmaps.map.map_options.auto_adjust = true;
Gmaps.map.initialize();
Gmaps.map.markers = [{"lat":40.7142,"lng":74.0064}];
Gmaps.map.markers_conf.do_clustering = true;
Gmaps.map.create_markers();
Gmaps.map.adjustMapToBounds();
Gmaps.map.callback();
};
Gmaps.oldOnload = window.onload;
 window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };

我确实收到了错误Uncaught TypeError: Object #&lt;Gmaps4RailsGoogle&gt; has no method create_markers

另外,这里是问题的图片(请注意地图上方的打印 json,如上面的视图代码中所做的那样):

【问题讨论】:

  • 我不知道rails或gmap4rails...生成的javascript是什么样的?
  • 谢谢,我已经相应地更新了我的帖子。
  • 您能否列出所有加载到您的视图中的 javascript 文件 - 只是为了确认所有 gmap4rails JS 文件都在那里?

标签: ruby-on-rails ruby ruby-on-rails-3 google-maps gmaps4rails


【解决方案1】:

我使用 Coffeescript 解决了这个问题。在我手动复制 javascript 文件之前,因为我不想在我的应用程序上使用 Coffeescript。

我的安装错误,使用 Coffeescript。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-23
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多