Search code examples
openlayers

How to move a marker in an OpenLayers.Layer.Markers layer?


How can I programmatically move an existing marker on an OpenLayers.Layer.Markers layer? I can't seem to find a proper way.

Is this supported at all? Or do I have to use the Vector layer?

The marker.moveTo() function doesn't work for me, I have the coordinate in lat/lon.


Solution

  • marker.moveTo() is not "official" APIMethod. It's used internally by other methods in OpenLayers and you are actually discouraged to use methods that are not marked as "APIMethod".

    Wouldn't removing and adding marker on new position fulfill your requirement? There are removeMarker() and addMarker() APIMethods for that.

    If not, I would consider using Vector layer as it's much more flexible in terms om rendering and manipulation features.