title: Load google maps to div loaded by ajax
body: <p>I'm using jquery ajax to get some results from a php script that is parsing an xml document. After that ajax call i whant to show a map from google api, in a div created by that php script (<strong><em>that's my problem</em></strong>).</p>
  
  <p>Is it possible to load the maps API to the <code>&lt;div id="map-canvas"&gt;</code> that is created in php, after the ajax call??</p>
  
  <p><strong>PHP FILE</strong></p>
  
  <pre><code>    ... $xmlData = simplexml_load_file("using an http service");            
      echo "&lt;div id='map-canvas'&gt;&lt;/div&gt;";  //LOAD MAPP HERE!
      echo "&lt;ul&gt;";
      foreach($xmlData-&gt;StopTimes-&gt;StopTime as $stopTime){
          echo "&lt;li&gt;",$stopTime-&gt;attributes()-&gt;Hour,"&lt;/li&gt;";
      }
      echo "&lt;/ul&gt;";
  }
  </code></pre>
  
  <p><strong>AJAX FILE</strong></p>
  
  <pre><code>...
      //station click, show next stops
      $('.station_link').click(function(){
          var station_text = $(this).text();
          $.ajax({                                //make the ajax call
              type: "POST",                       //use POST/GET
              url: "../server_side/nextStop.php", //file to send data
              data: {poststation : station_text},         //postlink -&gt; php($_POST) value / text -&gt; jquery var value
              success: function(data){            //on success, do something
                  $('#next_stop').html(data);
                  $('#next_stop').show();
  
              //Google maps API
                   function initialize() {
                        var mapOptions = {
                          zoom: 8,
                          center: new google.maps.LatLng(-34.397, 150.644),
                          mapTypeId: google.maps.MapTypeId.ROADMAP
                        }
                        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
                      }
  
                      function loadScript() {
                        var script = document.createElement("script");
                        script.type = "text/javascript";
                        script.src = "http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;sensor=TRUE_OR_FALSE&amp;callback=initialize";
                        document.body.appendChild(script);
                      }
  
                      loadScript();
              }   
              });
          });
      });
  </code></pre>
  
  <p>This is what i've tried (and much more :p), but i dont even know if its just wrong.</p>
  
  <p>Any help or advise would be appreciated!</p>
  
  <p><strong>-- UPDATE --</strong></p>
  
  <p>As simple as this:</p>
  
  <p><strong>javascript file</strong></p>
  
  <pre><code>//station click, show next stops
      $('.station_link').click(function(){
          var station_text = $(this).text();
          $.ajax({                                //make the ajax call
              type: "POST",                       //use POST/GET
              url: "../server_side/nextStop.php", //file to send data
              data: {poststation : station_text}, //postlink -&gt; php($_POST) value / text -&gt; jquery var value
              success: function(data){            //on success, do something
                  $('#next_stop').html(data);
                  $('#next_stop').show();
  
  
                  // Google maps API
                  var mapOptions = {
                      center: new google.maps.LatLng(37.7831,-122.4039),
                      zoom: 12,
                      mapTypeId: google.maps.MapTypeId.ROADMAP
                  };
  
                  new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  
              }   
              });
          });
      });
  </code></pre>
  
  <p>And just adding this <code>&lt;script src="https://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;</code> to the HTML file.</p>
  
  <p>That's what i whanted, it´s loading the <code>&lt;div id="map-canvas"&gt;</code> as it should.</p>
  
  <p>Ty for help anyway!
  Sorry if i didn't proove my point earlier, i'm a bit newbie ;)</p>