title: Move marker dynamically
body: <p>I am using <code>Openlayers.Layer</code> and <code>OpenLayers.Marker</code> to display a marker on the map.</p>
  
  <p>It is positioned correctly and I can successfuly show it and hide it doing:</p>
  
  <p><code>marker.display(boolean);</code></p>
  
  <p>But I try to <strong>change its position</strong> before displaying it but with no success. I already tried this:</p>
  
  <pre><code>var projections = {
      g: new OpenLayers.Projection("EPSG:4326"),
      p: new OpenLayers.Projection("EPSG:900913")
  };
  var newlonlat = new OpenLayers.LonLat(newlon, newlat).transform(projections.g, projections.p);
  </code></pre>
  
  <p></p>
  
  <pre><code>marker.lonlat = newlonlat
  layer.redraw();
  </code></pre>
  
  <p>(no errors triggered but position does not change)</p>
  
  <p>and also tried this:</p>
  
  <pre><code>var px = map.getPixelFromLonLat(newlonlat);
  marker.moveTo(px);
  layer.redraw();
  </code></pre>
  
  <p>(it throws an error inside <code>getPixelFromLonLat</code> function. Error: <code>c is null</code>)</p>
  
  <p>Why can't I <strong>move markers dynamically</strong> and what is the best way to do it?</p>
  
  <h3>Edit:</h3>
  
  <p>Maybe the problem resides in my position projection transformation when using second option:
  <code>new OpenLayers.LonLat(newlon, newlat).transform(projections.g, projections.p);</code></p>
  
  <h3>Edit 2</h3>
  
  <p>So, going deeper I found that <code>marker.map</code> property was <code>null</code>, so after its initialization I did:</p>
  
  <pre><code>var marker = new OpenLayers.Marker(lonlat, icon);
  marker.map = map;
  </code></pre>
  
  <p>where map is an <code>OpenLayers.Map</code> object and now its working fine. Don't know why but it fixed it.</p>