1

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 (匿名関数)

何午前私は行方不明?おかげ

ステファンあなたが何をすべき

答えて

0

setInterval(function(){ 
Gmaps.map.createMarker({ 
    Lat: Gmaps.map.userLocation.lat(), 
    Lng: Gmaps.map.userLocation.lng(), 
    rich_marker: null, 
    marker_picture: "https://a248.e.akamai.net/assets.github.com/images/modules/about_page/octocat.png?1315937507", 
    marker_width: 80, 
    marker_height: 80, 
    marker_anchor: null, 
    shadow_anchor: null, 
    shadow_picture: null, 
    shadow_width: null, 
    shadow_height: null 
    })},10000) 

冗長なく、直接使用されることになっていませんでした:)

はところで、それは良いの実装ではありません。

何ユーザーがジオロケーションを受け入れるのに時間がかかる場合(または単に拒否した場合)

+0

yep.Doのトリック!あなたはLT実装ではありません。私はちょうど私のジオロケーションが現れるようにしたかった。この良質のGmaps4rails gemをありがとう。本当に役に立ちました – Stephane

+0

これは表示に時間がかかりますが、表示される方が速いものがありますか? – locoboy

+0

@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

関連する問題