Search code examples
androidgoogle-mapsandroid-mapviewitemizedoverlay

MapView marker slightly moves when zooming out


I'm using Google Map for my application. Using the exact code in this guide from Google itself, I managed to put a marker on the map using ItemizedOverlay.

But when I zoom out, the marker slightly moves to the left. The Circle Radius Overlay stay in place though

Here's a screenshoot of my app:

Zoomed in---------Zoomed out

It does not happen in the real Google Map apps:

enter image description here----enter image description here

I tried using hard-coded Geo point but the marker still slightly moves. Anybody know the solution of this?

Thanks

[EDIT]

Here's my ItemizedOverlay class

public class MyItemizedOverlay extends ItemizedOverlay {
    private ArrayList<OverlayItem> overlays = new ArrayList<OverlayItem>();
    Context context;

    public MyItemizedOverlay(Drawable marker) {
        super(boundCenterBottom(marker));
    }

    public MyItemizedOverlay(Drawable marker, Context context) {
        super(boundCenterBottom(marker));
        context = context;
    }

    public void addOverlay(OverlayItem overlay) {
        overlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return g_overlays.get(i);
    }

    @Override
    public int size() {
        return overlays.size();
    }

    protected boolean onTap(int i) {
        //...
    }
}

and here's the code that calls the above class

List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.map_pin);
MyItemizedOverlay mio = new MyItemizedOverlay(drawable, this);
OverlayItem oi = new OverlayItem(mGeoPoint, "Your location", "");
mio.addOverlay(oi);
mapOverlays.add(mio);

Solution

  • Just found out that the cause of this is boundCenterBottom inside ItemizedOverlay constructor

    I changed it to boundCenter and it stays in place after zooming out

    public MyItemizedOverlay(Drawable marker) {
        super(boundCenter(marker));
    }