Reputation: 131
I've seen some posts that address similar topics, but not close enough for me to apply to my site. I'd like a certain infowindow to open when loading the map on this page: http://www.wrh.noaa.gov/mfr/rec.
I'd like to pass a url parameter (am already doing so for zoom, center, etc) that will open a specific infowindow onload without changing the overall functionality of the page (if no url parameter is passed for infowindow).
Thanks for any help. I imagine I'll have to do a fair bit of editing b/c I've got multiple variables displaying on the infowindow (associated with the xml element...I get most of the content for the markers from my xml document) and below the map with the forecast.
I don't think I was totally clear with my question. I'll rephrase: Sean, Thanks so much. I don't want to create another webpage with just the one infowindow opening, which I think is what you're suggesting. I have customers that want my map zoomed in with only one recreation site (marker) showing, the infowindow open, and the forecast displaying below the page. Here's an example of what I want (url parameters setting the zoom and center values), but I can't get the infowindow of the only marker shown in the map to open. For instance, if I could code something where a URL like this: http://www.wrh.noaa.gov/mfr/rec/index.php?t=roadmap&lat=42.10053453772226&lng=-123.40782557983397&z=12&window=oregoncaves would display the zoomed in map AND open the infowindow. I just don't know how to go about this. Seems like I would have an if statement that checks if the URL parameter "window" equals "oregoncaves", then open that infowindow for that marker. Again, thanks for any help.
S
Upvotes: 0
Views: 600
Reputation: 7716
Your question mentions url parameters for zoom and center, but I've checked the page at your link and it is using the standard JavaScript v3 API for those, not url parameters.
That seems a little confusing, so I may be missing something, but if you want to create an InfoWindow
dev-guide that opens immediately, simply create the object the InfoWindow
api-doc will be associated with (usually a google.maps.Marker
api-doc) and then create the InfoWindow
right after the map is created (code largely taken from the Developer's Guide, with minor mods):
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 id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://en.wikipedia.org/w/index.php?title=Uluru</a> (last visited June 22, 2009).</p>'+
'</div>'+
'</div>';
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Uluru (Ayers Rock)"
});
var infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.open(map,marker);
Upvotes: 0