Reputation: 1902
Here is my function I created for gmaps
function createMap (qc,mess,ele){
var myLatLng = qc;
// Create a map object and specify the DOM element for display.
var map = new google.maps.Map(document.getElementById(ele), {
center: myLatLng,
scrollwheel: false,
zoom: 4
});
// Create a marker and set its position.
var marker = new google.maps.Marker({
map: map,
position: myLatLng,
title: mess
});
}
Here is what my PHP generates from my Database
<div id="1_map"></div>
<script>
var qc_1 = {lat:44.6309454, lng:-123.0913114};
createMap(qc_1,"text Message", "#1_map");
</script>
Order of load is Google Maps API Call, javascript file with createMap, and then PHP generated Text.
Uncaught TypeError: Cannot read property 'offsetWidth' of null
Upvotes: 0
Views: 242
Reputation: 4568
document.getElementById(ele)
doesn't need the hash symbol, I don't think.
try
createMap(qc_1,"text Message", "1_map");
not
createMap(qc_1,"text Message", "#1_map");
Upvotes: 1