Gmaps4railsを使用しています。それは本当にうまくいっています。しかし、今私はブラウザを使って私のユーザにgeolocateを試す際に問題があります。ブラウザによるユーザージオロケーションのgmaps4railsに関する問題
マイビュー:How do I display the user's location with a marker in gmaps4rails?
私gmapsコーヒースクリプト
detect_location: true # should the browser attempt to use geolocation detection features of HTML5?
center_on_user: true # centers map on the location detected through the browser
で説明したように
<%= gmaps(:markers => { :data => @json},
:map_options => { :container_class => "map_container",:id => "map",:class => "gmaps4rails_map"},
:scripts => :none) %>
<% content_for :scripts do %>
<script type="text/javascript">
Gmaps.map.callback = function() {
setInterval(function(){Gmaps.map.createMarker({
Lat: Gmaps.map.userLocation.lat(),
Lng: Gmaps.map.userLocation.lng(),
rich_marker: null,
marker_picture: "/images/icon.png",
})},10000)
}
</script>
<% end %>
私はグーグルで、このエラーを得たブラウザのジオロケーション遅延のためのsetIntervalメソッドを試してみましたクロムコンソール。
キャッチされない例外TypeError:プロパティを読み取ることができません '0' 未定義 Gmaps4Rails.Gmaps4Rails.createImageAnchorPositiongmaps4rails.base.jsの:377 Gmaps4RailsGoogle.Gmaps4RailsGoogle.createMarkergmaps4rails.googlemaps.js:127 (匿名関数)
何午前私は行方不明?おかげ
ステファンあなたが何をすべき
yep.Doのトリック!あなたはLT実装ではありません。私はちょうど私のジオロケーションが現れるようにしたかった。この良質のGmaps4rails gemをありがとう。本当に役に立ちました – Stephane
これは表示に時間がかかりますが、表示される方が速いものがありますか? – locoboy
@locoboyはいこちらをご覧ください: 'https://github.com/apneadiving/Google-Maps-for-Rails/blob/1.x/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee#L99' 。 'Gmaps.map.geolocationSuccess'を' Gmaps.map.callback'を定義する方法で定義してください – apneadiving