I am using Mapsforge 0.5 for android. I have added some markers to the map with:
map.getLayerManager().getLayers().add(layer);
What I am trying to do is change the position of an existing layer. I have a reference to the object stored, but there isn't any way to move the marker. There is only a getter for the position
layer.getPosition() : LatLong
The latitude and longitude fields of LatLong are final :( I have solved the problem by first removing the layer and then adding it again but that results in some additional coordination logic. Is there some way I can actually move a Layer (Marker)?
Mapsforge treats layers to be anything like render layer, tile layer, map overlays like markers, etc.
The abstract class Layer defines the getPosition()
method to return null, by default.
Some classes extended from it like TileLayer
does not modify the method's behavior. But, some Layer's extended classes do modify it.
In your case, a map overlay type, the Marker class extends from Layer
with a modified getPosition()
method. The value of the private field Marker.this.latLong
is not even final. It accepts a change to Marker.this.latLong
via Marker.setLatLong()
method.
Provided that the Layer object is really an instance of Marker
, you can cast the object as Marker
.