【发布时间】:2017-04-01 17:45:15
【问题描述】:
我需要在地图中显示当前用户位置。我正在使用宝石 gmaps4rails。这是我的观点,我只是在github上找到教程并在页面上构建地图,但在教程中没有关于用户定位功能的内容。
<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>
【问题讨论】:
标签: javascript ruby-on-rails google-maps gmaps4rails