2

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>
1

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

7 Comments

I'm using another template
What di you mean ? ..you are not able to place the code in right source/file? update you question with you template or files involved ...so i can suggestion where place the code .. ..
i'm using wordpress, i was created new page template which contains script google map
i get error in my console :You have included the Google Maps API multiple times on this page. This may cause unexpected errors. when i put code in header any idea ?
Try removing the first script <script src='maps.googleapis.com/maps/api/js?v=3.exp'></script>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.