Android - 谷歌地图标记四处移动

时间:2016-06-03 18:30:29

标签: android google-maps google-maps-markers

出于某种原因,我注意到我放大图标的标记在我放大和缩小时不会粘在他们的lon / lat上。但是,如果我使用项目中的资产,它就不会发生。有谁知道为什么?

我使用以下方式加载资产:

Picasso.with(mActivity).load(strUrl).into(currentMarker.getCurrentMarker());

- 编辑 -

public class CustomMarker implements Target {

    Marker mMarker;
    private boolean doneLoad;

    public CustomMarker(Marker marker) {

        mMarker = marker;
        doneLoad = false;
    }

    @Override
    public int hashCode() {
        return mMarker.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if(o instanceof CustomMarker) {
            Marker marker = ((CustomMarker) o).mMarker;
            return mMarker.equals(marker);
        } else {
            return false;
        }
    }

    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from)  throws IllegalArgumentException {

        if (doneLoad == false) {
            try {
                mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
                doneLoad = true;
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }

    }

    @Override
    public void onBitmapFailed(Drawable errorDrawable) {

    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {

    }


    public Marker getmMarker() {
        return mMarker;
    }

    public boolean isDoneLoad() {
        return doneLoad;
    }

    public void setDoneLoad(boolean doneLoad) {
        this.doneLoad = doneLoad;
    }
}

1 个答案:

答案 0 :(得分:1)

问题是图标锚定不正确。

setIcon上的CustomMarker.onBitmapLoaded之后添加此内容:

mMarker.setAnchor(0.5f,1f);