The markers on the map change position when map is rotated

*爱你&永不变心* 提交于 2019-12-25 17:21:51

问题


I added markers on my map :

ClusterLayer markersClusterLayer = new ClusterLayer();
Collection<MapMarker> markers = new ArrayList<>();
for (GeoCoordinate geoCoordinate : list.get(0).getRoute().getWaypoints()) {
    MapMarker marker = new MapMarker();
    marker.setCoordinate(geoCoordinate);
    markers.add(marker);
}
markersClusterLayer.addMarkers(markers);
map.addClusterLayer(markersClusterLayer);

When I rotate my map using my fingers on the device, the marker position changes slightly, going from one side of a road to another for example.

How can I fix it?

Thanks

Edit: video showing the problem: youtu.be/mhObjaq72GQ


回答1:


I found the issue, it was related to the altitude of the point.

I was using

PositioningManager.getInstance().getLastKnownPosition()

which returned a position with altitude. As a result the marker was "flying" above the map. Setting altitude to 0 fixed the issue.




回答2:


It's not evident from your code, but is it possible that you are using a custom icon for your MapMarkers? If so, remember that the anchor is set to the center of the image by default. This isn't always the correct position.

For example, if your marker image is an arrow, you want to set the anchor to the tip of the arrow. Otherwise it might appear to point to different locations when the map is rotated (event though its center will always be in the same spot). Setting an incorrect anchor can also lead to similar behavior.

You can change the anchor by using the setAnchorPoint method.



来源:https://stackoverflow.com/questions/37572251/the-markers-on-the-map-change-position-when-map-is-rotated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!