Search code examples
androidosmdroid

OSMDroid - Custom Marker moving as I zoom out


I have implemented OSMDroid and added a Custom Marker like this:

    mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
    mapView.setTileSource(TileSourceFactory.MAPNIK);
    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapController = this.mapView.getController();
    mapController.setZoom(25);
    GeoPoint center = new GeoPoint(DataManager.glat, DataManager.glon);
    mapController.setCenter(center);
    OverlayItem newItem = new OverlayItem("Here", "SampleDescription", center);
    Drawable newMarker = this.getResources().getDrawable(R.drawable.marker);
    newItem.setMarker(newMarker);

This marker should be at the user´s location and the map should be centered there by default. This works well, as long as I dont zoom:

Original Zoom (25)

But when I zoom out, the marker moves:
Zoomed out a bit

The distance increases with zoomlevel:
Zoomed out even further

Any idea what this is caused by? Are there any restrictions/guidelines for custom markers?

Note: This does NOT happen when using the default marker.


Solution

  • Found the problem: Hotspot

    Seems like the default Hotspot is Bottom Center, in my case, Center would be the right one. The bottom center of my marker WAS at the right place, it just didnt look like it.

    newItem.setMarkerHotspot(HotspotPlace.CENTER); fixed it

    This is basically my marker:

     ___________
    |     _     |
    |    ( )    |
    |     V     |
    |           |
    |___________|