Gmaps4rails位置集

问题描述:

我需要在地图上显示当前用户位置。我正在使用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> 

使用处理程序初始化地图我这样做

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(); 
 
    }); 
 
}

希望这个作品给你。