标签: gmaps4rails2

Gmaps4rails V2 - 更改默认缩放

我是一个完整的菜鸟,建立我的第一个rails应用程序.我使用youtube上的apneadiving教程成功实现了Google-maps-for-rails V2:http://www.youtube.com/watch?v = R0l-7en3dUw&feature = youtu.be

我的问题是,对于我的每张地图,我只显示一个标记,当地图加载时,它会调整为完全缩放.

搜索周围,似乎有很多早期版本的Gmaps4rails解决方案,但对于V2,并通过javascript创建地图,我似乎无法找到一个有效的解决方案.

作为参考,我的代码如下:

视图:

    <script type="text/javascript">
      handler = Gmaps.build('Google');
      handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
      markers = handler.addMarkers(<%=raw @hash.to_json %>);
      handler.bounds.extendWith(markers);
      handler.fitMapToBounds();
      }); </script> 
Run Code Online (Sandbox Code Playgroud)

控制器:

def show
  @pins = Pin.find(params[:id])
  @hash = Gmaps4rails.build_markers(@pins) do |pin, marker|
    marker.lat pin.latitude
    marker.lng pin.longitude
  end
end
Run Code Online (Sandbox Code Playgroud)

我试图通过控制台使用:gmap.setzoom(12)进行更改,正如某些帖子所建议的那样,但是没有任何运气.

任何帮助深表感谢

对我有用的答案:将视图更改为:

  <script type="text/javascript">
  handler = Gmaps.build('Google');
  handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
  markers = handler.addMarkers(<%=raw @hash.to_json %>);
  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();
  handler.getMap().setZoom(12);
  }); </script> 
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

ruby-on-rails gmaps4rails ruby-on-rails-4 gmaps4rails2

23
推荐指数
1
解决办法
6698
查看次数

gmap4rails - 找不到文件下划线/未定义Gmaps

我在这里遵循简单的教程:https://github.com/JonKernPA/gmaps

我一直收到错误:

couldn't find file 'underscore'
    (/app/assets/javascripts/application.js:16)
Run Code Online (Sandbox Code Playgroud)

突出显示以下行:

<%= javascript_include_tag "application", "data-turbolinks-track" => true %>  
Run Code Online (Sandbox Code Playgroud)

我尝试按照Gmaps中发布的建议 未在rails 4 + gmaps4rails 2.0.3中定义

并且突出显示相同行的错误时出现相同的错误.当我尝试删除该行

<%= javascript_include_tag "application", "data-turbolinks-track" => true %>  
Run Code Online (Sandbox Code Playgroud)

从application.html.erb,我收到错误"未找到Gmaps"

任何帮助表示感谢,谢谢.Github链接:https://github.com/chiefkikio/circus/

ruby-on-rails-3 gmaps4rails gmaps4rails2

5
推荐指数
2
解决办法
3018
查看次数

在rails 4 + gmaps4rails 2.0.3中未定义Gmaps

Gmaps4rails未在rails 4.0.0中定义Google Maps for Rails我遵循本教程" http://rubydoc.info/gems/gmaps4rails/2.0.4/frames "

1) Gemfile

gem 'gmaps4rails'

2) HTML on view page   
<div style='width: 800px;'>
  <div id="map" style='width: 800px; height: 400px;'></div>
</div>

3) on view page    
<script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
You'll require underscore.js too, see here: underscorejs.org/

3) Javascript source code

If you have the asset pipeline, add this:

//= require underscore
//= require gmaps/google
If you don't have asset pipeline, you'll need to import the js OR coffee files:

rails g gmaps4rails:copy_js

rails …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-4 gmaps4rails2

3
推荐指数
1
解决办法
4276
查看次数

gmaps4rails v2 fitMapToBounds()

如果我单击某些内容将5个标记添加到地图上,例如100英里 - 将添加标记,并缩小地图以适应所有标记.

如果我然后单击显示标记的内容,例如2英里......标记会正确消失,但地图不会缩放.

我正在使用2.1.1

这是我的javascript调用:

Gmaps.store.handler.removeMarkers(Gmaps.store.markers);
Gmaps.store.markers = Gmaps.store.handler.addMarkers(<%= raw @hash.to_json %>, {
  draggable: false,
  animation: google.maps.Animation.DROP
});
Gmaps.store.handler.bounds.extendWith(Gmaps.store.markers);
Gmaps.store.handler.fitMapToBounds();
Run Code Online (Sandbox Code Playgroud)

我错过了一个电话吗?我想removeMarkers现在清除了群集器?

javascript ruby-on-rails google-maps-api-3 gmaps4rails gmaps4rails2

0
推荐指数
1
解决办法
868
查看次数