I searched this question, and I found answer saying I need to put my code inside $(document).ready
function in order for the map to load properly
but what if I don't use Jquery? what if I only use Javascript? so I searched for the equivalent of $(document).ready
and found this answer
so I try writing a script with that function :
function initbdg() {
var myLatlngBDG = new google.maps.LatLng(-6.913947, 107.633825);
var mapOptionsBDG = {
zoom: 15,
center: myLatlngBDG,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: 0
}
var mapBDG = new google.maps.Map(document.getElementById("map-BDG"), mapOptionsBDG);
var markerBDG = new google.maps.Marker({
position: myLatlngBDG,
map: mapBDG,
title: 'PT. Buana Citra Abadi Bandung'
});
markerBDG.setMap(mapBDG);
};
document.addEventListener("DOMContentLoaded", function(event) {
google.maps.event.addDomListener(window, "load", initbdg);
});
but I still need to refresh the page several time.
is there any sure way to properly load Google Maps without refresh, especially if the users has slow internet connection because I'm pretty sure most of my user has slow internet connection