How do I make an infowindow automatically display as open with Google-Maps-for-Rails

后端 未结 4 1430
情歌与酒
情歌与酒 2021-01-21 23:46

I want to display a map with the infowindow box automatically displayed for the single marker on the page, much like http://code.google.com/apis/maps/documentation/javascript/ex

相关标签:
4条回答
  • 2021-01-22 00:22

    The callback function that worked for me:

    Gmaps.map.callback = function() {
          function openInfoWindow(){
            var m, marker;
            marker = Gmaps.map.markers[2];
            m = marker.serviceObject;
            marker.infowindow.open(Gmaps.map.map, m);
          }
          openInfoWindow();
    }
    
    0 讨论(0)
  • 2021-01-22 00:28

    I am trying to accomplish the same thing, except to just open the first marker out of a list of markers. So the code is almost the same. I've done what you suggested but it's not showing the info window.

    <%= gmaps4rails(@json) %>
    
    <% content_for :scripts do %>
      <script type="text/javascript" charset="utf-8">
        Gmaps.map.callback = function() {
            var marker = Gmaps.map.markers[0];
            var infowindow = marker.infowindow;
            infowindow.open(Gmaps.map.map, marker);
        }
      </script>
    <% end %>
    

    The map display find but the info window doesn't pop up upon initialisation as expected! Any ideas?

    Will

    0 讨论(0)
  • 2021-01-22 00:32

    Your code is almost perfect. Except that instead of:

     infowindow.open(Gmaps.map, marker);
    

    You should have:

     infowindow.open(Gmaps.map.map, marker);
    

    Indeed, Gmaps.map is a container, Gmap.map.map is the google object.

    I know these names are confusing. Sorry.

    PS: be sure to put this code under the gmaps call in your view.

    0 讨论(0)
  • 2021-01-22 00:45

    You are mixing Javascript and Ruby together. Take a look at your javascript debugger (you are using one right? If not, the web inspector in Chrome or safari is great, as is Firebug for Firefox) and you'll see it complaining.

    Without seeing your controller code I can't give you too many specifics, but take a look at this post and it might point you in the right direction.

    0 讨论(0)
提交回复
热议问题