title: Update markers from google maps using codeigniter, Ajax, Javascript, Php
body: <p>I have a google map on my website created in codeigniter. Now I want to move the markers with data from my sql database. The data in my database will be updated. I can draw markers on the map by biostall. Now I want to move them. </p>
  
  <p>So I load all the markers and pass them to my view to draw them with a ajax/javascript script. I get no errors but also no markers.. I'm not a pro in ajax and javascript so the problem needs to be there but I can't fix it.. Here's my code. The map should be updated each 3 seconds.</p>
  
  <p>My controller :</p>
  
  <pre><code>function render_maps() {
      $userid = $this-&gt;uri-&gt;segment(3);
      $userlevel = $this-&gt;user_model-&gt;get_user_level($userid);
      if ($userlevel &gt; 2) {
          $this-&gt;load-&gt;library('googlemaps');
          $this-&gt;googlemaps-&gt;initialize();
  
          #$this-&gt;marks();
  
          $config['zoom'] = 'auto';
          $data['map'] = $this-&gt;googlemaps-&gt;create_map();
          $data['markers'] = json_encode($this-&gt;user_model-&gt;get_marks());
          $data['userdata'] = $this-&gt;session-&gt;userdata;
          $this-&gt;load-&gt;view('header', $data);
          $this-&gt;load-&gt;view('dashboard_maps', $data);
          $this-&gt;load-&gt;view('wrapper', $data);
      }
  }
  </code></pre>
  
  <p>My view : </p>
  
  <pre><code>&lt;head&gt;
       &lt;?php echo $map['js']; ?&gt;
       &lt;script type="text/javascript"&gt;
      function refreshMarkers() {
           $.ajax({
                url: "&lt;?php site_url('User/render_maps/'. $this-&gt;session-&gt;userdata('user_id')) ?&gt;",
                type: "POST",
                data: ({value: $markers}),
                dataType: "json", //retrieved Markers Lat/lng in Json, thus using this dataType
                success: function(data){
                    //Removing already Added Markers//////////
                   for (var i = 0; i &lt; $markers.length; i++) {
                       $markers[i].setMap(null);
                   }
                   $markers = new Array();
                   //////////////////////////////////////////
                    // Adding New Markers////////////////////
  
                    for (var i = 0, len = data.length; i &lt; len; ++i) { // Iterating the Json Array
                  var d = data[i];
  
                  var lat = parseFloat(d.lat);
                  var lng = parseFloat(d.lng);
                  var myLatlng = new google.maps.LatLng(lat, lng);
  
                  var marker = {
                      map: map,
                      position: myLatlng // These are the minimal Options, you can add others too
                  };
                  createMarker(marker);
              }
          }
      }
      );
  &lt;/script&gt;
  </code></pre>
  
  <p></p>