2017-04-01 38 views
0

我需要在地圖上顯示當前用戶位置。我正在使用gem gmaps4rails。這是我的觀點,我只是在github上找到教程並在頁面上構建地圖,但在教程中沒有關於用戶位置功能的說法。Gmaps4rails位置集

      <script src="//maps.google.com/maps/api/js?key=my api key"></script> 
          <script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script> 
          <script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script> 
         <p id="notice"><%= notice %></p> 

          <div style='width: 320px;'> 
          <div id="map" style='width: 320px; height: 400px;'></div> 
         </div> 

         <script type="text/javascript"> 
          handler = Gmaps.build('Google'); 
          handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 
           var markers = handler.addMarkers(<%=raw @hash.to_json %>); 
           handler.bounds.extendWith(markers); 
           handler.fitMapToBounds(); 
          }); 
         </script> 

回答

0

使用處理程序初始化地圖我這樣做

handler.map.centerOn({ lat: 5.574076, lng: -75.5926227 }) 

在這裏你可以找到更多信息 https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Js-Methods

function intializeMap(){ 
 
    handler = Gmaps.build('Google'); 
 
    handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 
 
    markers = handler.addMarkers("the DATA here"); 
 
    handler.bounds.extendWith(markers); 
 
    handler.map.centerOn({lat: 5.574076, lng: -75.5926227}); 
 
    handler.fitMapToBounds(); 
 
    }); 
 
}

希望這個作品給你。

相關問題