1

Gmaps4rails を使用しています。それは本当にうまくいっています。しかし、ブラウザを介してユーザーの位置情報を取得しようとすると問題が発生しました。

私の見解:

   <%= 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 %>

gmaps4railsでマーカーを使用してユーザーの位置を表示するにはどうすればよいですか? で説明されているように、ブラウザーの地理位置情報遅延の setinterval メソッドを試しました

私の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

Google Chrome コンソールでこのエラーが発生しました。

キャッチされていない TypeError: 未定義の Gmaps4Rails.Gmaps4Rails.createImageAnchorPositiongmaps4rails.base.js:377 のプロパティ '0' を読み取れません Gmaps4RailsGoogle.Gmaps4RailsGoogle.createMarkergmaps4rails.googlemaps.js:127 (無名関数)

何が欠けていますか?? ありがとう

ステファン

4

1 に答える 1

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)

詳細ですが、直接使用することは想定されていません:)

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

ユーザーが地理位置情報を受け入れるのに時間がかかる (または単に拒否する) 場合はどうなりますか?

于 2012-04-14T21:02:36.710 に答える