English 中文(简体)
页: 1
原标题:Google maps open info window by default?

The following example shows a simple Marker (standard icon) on Google maps for the location and when clicking the icon, it opens the info window. Can I show the info window open by default so that I don t need to click the icon to open?

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
    var myOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var contentString =  <div id="content"> +
         <div id="siteNotice"> +
         </div> +
         <h2 id="firstHeading" class="firstHeading">Uluru</h2> +
         </div> ;

    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title:"Uluru (Ayers Rock)"
    });

    google.maps.event.addListener(marker,  click , function() {
    infowindow.open(map,marker);
    });
最佳回答

If you want to show the info window opened by default without click, just add a new code like bellow:

页: 1

google.maps.event.addListener(marker,  click , function() {
        infowindow.open(map,marker);
});

因此,我们有这样的新法典:

google.maps.event.addListener(marker,  click , function() {
   infowindow.open(map,marker);
});

infowindow.open(map,marker);

各位可以看到,我们只添加一条与infowindow open(地图、标识);的小条。

问题回答

您可以在网页上直接操作“开放”,而不必点击便自动打开窗户。

infowindow.open(map, marker);

然而,在某些情况下,这可能无法使地图适当自动化,使地图上层的超支处于边缘。

A way that worked for me is to wrap it in a listener to the "tilesloaded" event on the map

google.maps.event.addListenerOnce(map,  tilesloaded , function() {
  infowindow.open(map, marker);
});

以上法典完全有效。 然而,我的地图正直下调,以便全面显示Infowindow。 相反, push子留在中间。

So how do you make the map adjust itself so the info window is fully viewable? Read this: Google Maps : auto center map on marker click

If you want the pushpin to stay where it is and not shift the map, read this: Google Maps: How to prevent InfoWindow from shifting the map

帮助人们的希望下一步

《刑法》 对我课以罚款:

Change latitude, longitude, Content and mapid (with your custom div id):

<script type="text/javascript">

function initialize() {
    var myLatlng = new google.maps.LatLng(48.206615,13.487928);
    var mapOptions = {
        zoom: 16,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById( map-canvas ), mapOptions);

    var contentString =  <p><strong>Bahnhofstraße 32</strong></p><p>Bahnhofstraße 32, 4910 Ried im</p><p>Innkreis, Austria</p> ;

    var infowindow = new google.maps.InfoWindow({
      content: contentString
  });


    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title:  Bahnhofstraße 32 
    });

    google.maps.event.addListener(marker,  click , function() {
    infowindow.open(map,marker);
  });
  // show map, open infoBox 
        google.maps.event.addListenerOnce(map,  tilesloaded , function() {
          infowindow.open(map, marker);
        });

}

google.maps.event.addDomListener(window,  load , initialize);

    </script>




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签