I am trying to align an image to the center of a google map div.
Basically this image is to apply the same functionality as Uber. as in having a floating marker that is always aligned to the center of the map. The problem is i can fix it to work for one map size. but if the size of the map div is changed then the image doesn't point to the center of the map anymore.
here's how it works in uber. https://youtu.be/U9A86Nh75xQ?t=36s
here is my sample body code
<body>
<div id="map"></div>
<div id="static-img">
<img src="http://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-poi.png">
</div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 28.625789, lng: 77.0547899},
zoom: 8
});
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
title: 'Hello World!'
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
async defer></script>
this is the css
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
#static-img{
position:absolute;
top:44%;
width:100%;
text-align:center;
}
here is a test jsfiddle https://jsfiddle.net/pyu8rqso/1/
How should i go about fixing this one?