I am using bootstrap for layout and i am trying to center my map to a marker, but the problem is that the marker shows up at the bottom of the map container. If i slightly resize the window then it centers itself and work normally.
my mark up
<div id="gMap">
<div id="map-canvas"></div>
</div><!--gMap-->
css
#map-canvas {
position: relative;
padding-bottom: 70%;
}
#map-canvas iframe {
width: 100% !important;
height: 100% !important;
}
js
var respMap;
var mapCanvas = document.getElementById('map-canvas');
function mymapini() {
var mapPos = new google.maps.LatLng(43.724243, -79.634353); //Set the coordinates
var mapOpts = {
zoom: 16,
disableDefaultUI: true,
center: mapPos,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
respMap = new google.maps.Map(mapCanvas,
mapOpts);
var mapMarker = new google.maps.Marker({
position: mapPos,
map: respMap,
title: 'Test marker'
});
google.maps.event.addListener(respMap, 'idle', function() {
window.setTimeout(function() {
respMap.panTo(mapMarker.getPosition());
}, 250);
});
}
if(mapCanvas != null){
google.maps.event.addDomListener(window, 'load', mymapini);
}