我试图创建一个带有多个标记的谷歌地图,一次只允许一个信息窗口.标记是IP摄像机的位置,它们通过红宝石获取.我已经阅读了类似问题的大量答案,解决方案是只创建一个信息窗口并重新使用它.
我试图从其他一些问题来实现这些解决方案,但我无法让它发挥作用.
$(document).ready(function () {
// execute
(function () {
// map options
var options = {
zoom: 2,
center: new google.maps.LatLng(25, 10), // centered US
mapTypeControl: false,
streetViewControl: false
};
// init map
var map = new google.maps.Map(document.getElementById('map-canvas'), options);
// set multiple marker
<% @cameras.each do |c| %>
// init markers
<% if c.deep_fetch(:location) {} != nil %>
var marker = new google.maps.Marker({
position: new google.maps.LatLng(<%= c.deep_fetch(:location, :lat) {} %>, <%= c.deep_fetch(:location, :lng) {} %>),
map: map,
title: 'Click …Run Code Online (Sandbox Code Playgroud) javascript google-maps-api-3 google-maps-markers ruby-on-rails-4