-1

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

Community
  • 1
  • 1
Citra45Abadi
  • 197
  • 1
  • 2
  • 20
  • why the downvote? there should be many people who wants to know how to write the script so that google map API will load without refreshing the page – Citra45Abadi Mar 04 '17 at 02:52

1 Answers1

1

This should be enough:

document.addEventListener("DOMContentLoaded", function() { 
    initbdg();
});
HoffZ
  • 7,500
  • 6
  • 33
  • 38