1
ユーザーの現在地にマーカーを配置しようとしています。Google Maps for Rails - コールバックにユーザーの場所があるマーカーを置く
しかし、私はコールバックでユーザーの場所を取得することもできません。 ブラウザのジオコーディングの前に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>
私が問題を抱えているパッチの例を提供できるなら、これはうまくいくでしょう –
これは宝石に追加されました:https://github.com/apneadiving/Google-Maps-for-Rails/コミット/ e4815ee22e0586f7d6527a1e0443691fb769f114 – apneadiving