Loding Google Map via php

Hello,

this is a basic html file that loads a google map. my problem is, if this goes in to a php files as shown below, it does not load. can any one pls have a look?

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map-canvas { height: 100% }
    </style>
  </head>
  <body>

    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA6ANjvY-ldlqgM27iEz1s7_FRkVcir8ec&sensor=true">
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8,
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  
    <div id="map-canvas"/>
  </body>
</html>

same thing in php

echo "
    <script type=\\"text/javascript\\"
      src=\\"https://maps.googleapis.com/maps/api/js?key=AIzaSyA6ANjvY-ldlqgM27iEz1s7_FRkVcir8ec&sensor=true\\">
    </script>
    <script type=\\"text/javascript\\">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8,
        };
        var map = new google.maps.Map(document.getElementById(\\"map-canvas\\"),
            mapOptions);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>


 <div id=\\"map-canvas\\"/></div>
</div>";	

:frowning:

A couple of things I would try:
1/ Use V3 instead of V2? you do not need a key for that.
2/ Put the javascript into the header section

It will work with php as I have v2 and V3 working on different sites but I would not use your php version as it only confuses things.

Hello,

i changed the page layout and now i am only passing the cordinates via php and it works.

Out of interest I am currently making a new map and am using the method on this page which is very interesting.