Reputation: 67
I get error in my console when using google map api:-Uncaught ReferenceError: initialize is not defined Any help please ?
JS
<script type="text/javascript">
function initialize() {
var myLatLng = {lat: 42.52501, lng: 2.938979};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: myLatLng,
scrollwheel: false,
draggable:true,
});
var image='logo.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon:image
});
}
</script>
HEADER.PHP
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key='YOUR API KEY HERE'"></script>
<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script>
<body onload="initialize()";></body>
Upvotes: 2
Views: 6079
Reputation: 133400
You call two time the google maps api , have body without code and is not clear where is placed the script with initialize function ...
i have played a litte with your code ..
HEADER.PHP
<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script>
<body>
<div id="map" style="height:500px; width:500px;"></div>
<script>
function initialize() {
var myLatLng = {lat: 42.52501, lng: 2.938979};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: myLatLng,
scrollwheel: false,
draggable:true,
});
var image='logo.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon:image
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
Upvotes: 2