SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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?

    Code:
    <!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

    PHP Code:
    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>"


  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,406
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    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.

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello,

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

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,406
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Out of interest I am currently making a new map and am using the method on this page which is very interesting.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •