【发布时间】:2012-03-30 10:16:55
【问题描述】:
我正在尝试在用户当前位置上放置一个标记。
但是,我什至无法在回调中获取用户位置。 似乎在浏览器的地理编码之前触发了console.log调用 我做错了什么?
haml 视图
= gmaps(:map_options => {:center_on_user => true})
- content_for :scripts do
:javascript
Gmaps.map.callback = function () {
console.log(Gmaps.map.userLocation)
}
html 输出
<div class="map_container">
<div id="map" class="gmaps4rails_map"></div>
</div>
<script type="text/javascript" src="//maps.google.com/maps/api/js?v=3.5&sensor=false&libraries=geometry"></script>
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script>
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js"></script>
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
<script type="text/javascript" charset="utf-8">
Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
Gmaps.map.map_options.center_on_user = true;
Gmaps.map.initialize();
Gmaps.map.adjustMapToBounds();
Gmaps.map.callback();
};
window.onload = function() { Gmaps.loadMaps(); };
</script>
<script>
//<![CDATA[
Gmaps.map.callback = function () {
console.log(Gmaps.map.userLocation)
}
//]]>
</script>
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 gmaps4rails