Center Google Maps InfoWindow On Load
HTML
<script src="https://maps.google.com/maps/api/js"></script>
<div id="map-canvas"></div>
CSS
html, body {
width: 100%;
height: 100%;
}
#map-canvas {
width: 100%;
height: 100%;
margin: 10px 0;
color: #000;
}
JavaScript
var geocoder = new google.maps.Geocoder();
var marker;
var infoWindow;
var map;
function initialize() {
var mapOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
setLocation();
}
function setLocation() {
var address = '2349 Marlton Pike W, Cherry Hill, NJ 08002';
geocoder.geocode({
'address': address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var position = results[0].geometry.location;
marker = new google.maps.Marker({
map: map,
position: position,
title: 'Venue Name'
});
map.setCenter(marker.getPosition());
var content = document.createElement('div');
var div = document.createElement('div');
div.id = "c_050e3e9d159498c53e6f88b44fad6987";
div.class = "normal";
content.appendChild(div);
var h2 = document.createElement('h2');
h2.style.color = "#000000";
h2.style.margin = "0 0 3px";
h2.style.padding = "2px";
h2.style.font = "bold 13px/1.2 Verdana";
h2.style.textAlign = "center";
h2.style.width = "100%";
div.appendChild(h2);
var a = document.createElement("a");
a.href = "http://www.forecast.co.uk/largs.html";
a.style.color = "#000000";
a.style.textDecoration = "none";
a.style.font = "bold 13px/1.2 Verdana";
a.innerText = "Forecast Largs";
div.appendChild(a);
var anotherDiv = document.createElement('div');
anotherDiv.id = "w_050e3e9d159498c53e6f88b44fad6987";
anotherDiv.class = "normal";
anotherDiv.style.height = "100%";
content.appendChild(anotherDiv);
var script = document.createElement('script');
script.src = "http://www.forecast.co.uk/widget/loader/050e3e9d159498c53e6f88b44fad6987";
content.appendChild(script);
infoWindow = new google.maps.InfoWindow({
content:...