Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 当未找到匹配项时,Gmaps4rails将退出海洋视图_Ruby On Rails_Gmaps4rails_Rails Geocoder_Gmaps4rails2 - Fatal编程技术网

Ruby on rails 当未找到匹配项时,Gmaps4rails将退出海洋视图

Ruby on rails 当未找到匹配项时,Gmaps4rails将退出海洋视图,ruby-on-rails,gmaps4rails,rails-geocoder,gmaps4rails2,Ruby On Rails,Gmaps4rails,Rails Geocoder,Gmaps4rails2,我正在尝试搜索10英里内的用户地址。只要距离在10英里以内,它就可以正常工作。但是,如果距离超过10英里,它就会飞到一个偏僻的地方。有没有办法解决这个问题,如果它不在范围内,它就不会缩放到随机的海洋,最好给出一个消息,说在给定的半径内没有匹配 用户/控制器 class UsersController < ApplicationController def index if params[:search].present? @users = User.near(par

我正在尝试搜索10英里内的用户地址。只要距离在10英里以内,它就可以正常工作。但是,如果距离超过10英里,它就会飞到一个偏僻的地方。有没有办法解决这个问题,如果它不在范围内,它就不会缩放到随机的海洋,最好给出一个消息,说在给定的半径内没有匹配

用户/控制器

class UsersController < ApplicationController
  def index
    if params[:search].present?
      @users = User.near(params[:search], 10)
    else
      @users = User.all
    end

    @hash = Gmaps4rails.build_markers(@users) do |user, marker|
      marker.lat user.latitude
      marker.lng user.longitude
      marker.infowindow user.description
    end
  end
end
class UsersController
index.html.erb

<div id="map-container">
  <div id="map-canvas"></div>
</div>

<%= form_tag users_path, :method => :get do %>
  <p>
  <%= text_field_tag :search, params[:search] %>
  <%= submit_tag "Search Near" %>
  </p>
<% end %>


<script>
$(document).ready(function(){
  handler = Gmaps.build('Google');
  handler.buildMap({ provider: {}, internal: {id: 'map-canvas'}}, function(){
    markers = handler.addMarkers(<%=raw @hash.to_json %>)
    handler.bounds.extendWith(markers);
    handler.fitMapToBounds(markers);
    if(navigator.geolocation)
      navigator.geolocation.getCurrentPosition;
  });
});
</script>

:get-do%>

$(文档).ready(函数(){ handler=Gmaps.build('Google'); buildMap({provider:{},内部:{id:'map canvas'}},函数(){ markers=handler.addMarkers() handler.bounds.extendWith(markers); handler.fitMapToBounds(标记); if(导航器.地理位置) navigator.geolocation.getCurrentPosition; }); });
那么,实际地图正在缩小?你能在视图中发布什么
@hash
输出吗?是的,当没有找到匹配项时,默认情况下它会放大到海洋中。你使用的是gmaps4rails v1还是v2?另外,请在您的问题中显示
@hash
的输出。那么,实际地图是否正在缩小?你能在视图中发布什么
@hash
输出吗?是的,当没有找到匹配项时,默认情况下它会放大到海洋中。你使用的是gmaps4rails v1还是v2?另外,请在您的问题中显示
@hash
的输出