title: Passing Data EventSource Server Sent Event (SSE) as another variable
body: <p>I have a web page that update latitude,longitude from database every X seconds and display the values. I'm using Server-Sent Event to update the value. My Server-Sent Event not have any problem. It can update latitude,longitude and speed on page every X seconds. My problem is I want to pass the latitude, longitude value to google map script to add a marker. How can I do it?</p>
  
  <p>Example this script will retrieve latitude value from database.</p>
  
  <pre><code>latitude.onmessage = function(e) {
      //document.getElementById("latitude").innerHTML += e.data + '&lt;br /&gt;';
      ('#latitude').text(e.data);
  }; 
  </code></pre>
  
  <p>How can I pass the latitude value to this code.</p>
  
  <pre><code>var marker = new google.maps.Marker({
      position: new google.maps.LatLng(LATITUDE VALUE, LONGITUDE VALUE),
      map: map
  }); 
  </code></pre>
  
  <p>Below is the full code</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;p&gt;Example server sent event&lt;/p&gt;&lt;br&gt;
      Latitude: &lt;span id="latitude"&gt;&lt;/span&gt;&lt;br&gt;
      Longitude: &lt;span id="longitude"&gt;&lt;/span&gt;&lt;br&gt;
      Speed: &lt;span id="speed"&gt;&lt;/span&gt;
  
      &lt;div id="map" style="width:100%;height:380px;"&gt;&lt;/div&gt;&lt;script&gt;
  
                      function initialize()
                      {
                          var latitude = new EventSource("&lt;?php echo base_url() . 'sse_push/getLatitude'; ?&gt;");
                          var lgt;
                          var lat;
                          latitude.onmessage = function (e) {
                              //document.getElementById("latitude").innerHTML += e.data + '&lt;br /&gt;';
                              $('#latitude').text(e.data);
                          };
                          var longitude = new EventSource("&lt;?php echo base_url() . 'sse_push/getLongitude'; ?&gt;");
                          longitude.onmessage = function (e) {
                              //document.getElementById("longitude").innerHTML += e.data + '&lt;br /&gt;';
                              $('#longitude').text(e.data);
                          };
                          var speed = new EventSource("&lt;?php echo base_url() . 'sse_push/getSpeed'; ?&gt;");
                          speed.onmessage = function (e) {
                              //document.getElementById("speed").innerHTML += e.data + '&lt;br /&gt;';
                              $('#speed').text(e.data);
                          };
  
                          var map = new google.maps.Map(document.getElementById('map'), {
                              zoom: 10,
                              center: new google.maps.LatLng(-33.92, 151.25),
                              mapTypeId: google.maps.MapTypeId.ROADMAP
                          });
  
                              var marker = new google.maps.Marker({
                                  position: new google.maps.LatLng(lat, lgt),
                                  map: map
                              });
  
                          marker.setMap(map);
                      }
                      google.maps.event.addDomListener(window, 'load', initialize);
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>