开发者

How to save Map Overlay and Current Map-Center on Screen Orientation in Android?

I am trying to create a map activity with an overlay image on the user location. Currently, I can maintain the map state when the screen is rotated by returning mapV.getMapCenter() in onRetainNonConfigurationInstance.

But how can I save both the map state and the user locatio开发者_如何学Cn (Overlay image) when the screen is rotated?


User a holder object.

private class Holder{
    public Overlay image;
    public GeoPoint center;

    public Holder(Overlay image, GeoPoint center){
        this.image = image;
        this.center = center;
    }
}

@Override
public Object onRetainNonConfigurationInstance() {
    return new Holder(image, center);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    Holder holder = (Holder) getLastNonConfigurationInstance();
    if (holder != null) {
            overlay = new ItemOverlay();
            overlay.setFocus(holder.overlay.getFocus());

            mapOverlays.add(overlay);
            }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜