如何在 gmaps4rails 中使用标记显示用户的位置? [英] How do I display the user's location with a marker in gmaps4rails?
问题描述
我一直在尝试自定义使用 gmaps4rails 运行,并且我已将代码设置为在地图上显示我的 json 坐标字符串,并且用户的中心正在工作,我可以在家中放大我的位置,工作和我的手机.一旦获得许可,我就无法让 js 正确地在地图上显示我在这里"按钮.
I have been trying to get a custom use of gmaps4rails running, and I have the code set to display my string of json coordinates on the map, and the center on user IS working, I can zoom into my location from home, work and my phone. I just cannot get the js right to display an 'Im here' button on the map once permission is given.
这是我用于 gmaps4rails 地图的代码:
here is the code I use for the map from gmaps4rails:
<%= gmaps(:map_options => {:detect_location => true, :center_on_user => true, :auto_zoom => false, :zoom => 12, :auto_adjust => true}, :markers => {:data => @json} ) %>
感谢您的帮助!
回答后编辑 12 月 6 日:
EDIT Dec.6 after answer:
我正在为回调添加代码:
I am adding in the code for the callback as so:
<script type="text/javascript" charset="utf-8">
Gmaps.map.callback = function() {
Gmaps.map.createMarker({Lat: Gmaps.map.userLocation.lat(),
Lng: Gmaps.map.userLocation.lng(),
rich_marker: null,
marker_picture: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/heart30.png"
})
}
</script>
仍然没有在地图上得到回应.这是我的js编码有问题吗?我还不是专业人士.
and still not getting a response on the map. Is this a problem with my js coding? I'm not pro yet.
谢谢!
推荐答案
您可以这样做:
Gmaps.map.createMarker({Lat: Gmaps.map.userLocation.lat(),
Lng: Gmaps.map.userLocation.lng(),
rich_marker: null,
marker_picture: ""
})
在回调中.
请注意,您可以传递所需标记的网址.
Notice you can pass the url of your desired marker.
顺便说一句,如果你觉得这是一个有用的功能,你应该在 github 上创建一个问题.
BTW, you should create an issue on github if you feel like this is a useful feature.
这篇关于如何在 gmaps4rails 中使用标记显示用户的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!