1
我正在使用Gmaps4rails。它工作得很好。但是现在我在通过浏览器尝试对用户进行地理定位时遇到了问题。用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 %>
我尝试了浏览器地理位置延迟的setInterval方法在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
我在谷歌得到这个错误镀铬控制台。
遗漏的类型错误:无法读取属性 '0' 未定义 Gmaps4Rails.Gmaps4Rails.createImageAnchorPositiongmaps4rails.base.js的:377个 Gmaps4RailsGoogle.Gmaps4RailsGoogle.createMarkergmaps4rails.googlemaps.js:127 (匿名函数)
上午什么我错过了?由于
斯特凡
是的,这是绝招!你说得对,它不是LT的实现。我只是想让我的地理位置出现。感谢这个不错的Gmaps4rails宝石。真的有帮助 – Stephane 2012-04-15 23:07:25
这需要一段时间才能看到它,有什么东西是更快的出现? – locoboy 2012-11-24 07:50:59
@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 2012-11-24 08:46:40