根据地理位置填充Google Maps for Rails标记

|| 我正在尝试使用Google Maps for Rails gem根据基于使用当前位置的自定义gmaps4rails_callback填充带有标记的地图,但是我似乎无法获得替换用户在触发用户后触发标记的代码\的地理位置已确定。 我的
application.js
定义了一个自定义地图回调函数,以及
getCurrentPosition
的回调:
function nearby_locations(position) {
    $.getJSON(\'locations/nearby.json\',
          { lat: \"33.7012\", long: \"-117.8683\" },
          function(data) {
                    Gmaps4Rails.replace_markers(data);
          });   
}

function gmaps4rails_callback() {
    navigator.geolocation.getCurrentPosition(nearby_locations);
}
目前,我使用的是硬编码的经/纬度数据,但最终我要在传递给我的
position
对象中取消真实数据的输入。手动运行getJSON调用可以正常工作,我的
locations/nearby.json
返回正确格式的位置数据,该格式可以按预期更新标记。 我的视图模板仅使用
<%= gmaps(\"map_options\" => {\"auto_adjust\" => true, \"detect_location\" => true}) %>
现在,我意识到我可能通过使用detect_location然后调用
getCurrentPosition
进行了两次地理查找,但是在较早的尝试中,
gmaps4rails_callback
中的代码在浏览器(Safari)的地理定位权限尚未完成之前就已执行,所以我认为这将延迟执行,直到确定位置为止。 我以前显示的地图没有自定义的“ 7”字样,并且效果很好,所以我知道我的jQuery和JavaScript文件都很好。 Google Maps for Rails是否有可能已经以某种方式设置了自己的“ 1”回调,而我的却被忽略了?添加一些调试日志后,看起来好像根本没有调用“ 10”。     
已邀请:
基本上,当您设置
\"detect_location\" => true
时,将触发以下功能:
findUserLocation: function() {
    if(navigator.geolocation) {
    //try to retrieve user\'s position
    navigator.geolocation.getCurrentPosition(function(position) {
      //saves the position in the userLocation variable
      Gmaps4Rails.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
           //change map\'s center to focus on user\'s geoloc if asked
            if(Gmaps4Rails.map_options.center_on_user === true) {
                Gmaps4Rails.map.setCenter(Gmaps4Rails.userLocation);
            }
    },
    function() {
          //if failure, triggers the function if defined
          if(this.fnSet(\"gmaps4rails_geolocation_failure\")) { gmaps4rails_geolocation_failure(true); }
        });
  }
  else {
      //if failure, triggers the function if defined
      if(this.fnSet(\"gmaps4rails_geolocation_failure\")) { gmaps4rails_geolocation_failure(false); }
  }
}
所以是的,地理位置定位已经完成或正在进行中。此功能在ѭ7之前触发,但这是浏览器地理位置的难点:需要花费不确定的时间。 我曾考虑过建议对失败进行回调,但是认为没有必要在成功上包含回调(我仍然不相信)。 不幸的是,我不理解您的ѭ14的问题:我同时拥有ѭ15和回调,并且按预期工作。     

要回复问题请先登录注册