I found that the map.snapshot () method only works under special conditions. If it is called too early, it will fail, if it is called at the end, and soon after installing the camera, it will return a snapshot of the wrong map image. I expect a snapshot to restore a snapshot map, determined last preset camera position and polylines. However, it is difficult to make the GoogleMap class wait, if he chooses the right pieces. Easy, if the user presses the button to create the snapshot because the user know when the card is ready, the more difficult, if it happens in software.
If you have CameraPosition (LatLng, zoom), it works well if MapFragment created using GoogleMapOption:
GoogleMapOptions googleMapOptions = new GoogleMapOptions(); googleMapOptions.liteMode(true).mapType(GoogleMap.MAP_TYPE_NORMAL); // if this is what you want googleMapOptions.camera(new CameraPosition(new LatLng(56, 10), 11, 0, 0)); MapFragment.newInstance(googleMapOptions);
If you do not have CameraPosition, it is more difficult. Perhaps you can not be CameraPosition, if it is designed so that these markers contained in the chamber, because for this calculation is required to GoogleMap been initialized width / height. (A problem with the chicken and the egg, or do it yourself).
Subclass MapFragment and overwrite onCreate
public class FixedMapFragment extends MapFragment { public void setOncreateListener(Listener listener) { this.listener = listener; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); if (listener != null) { listener.onCreate(v, mMapManager); } return v; } } , savedInstanceState); public class FixedMapFragment extends MapFragment { public void setOncreateListener(Listener listener) { this.listener = listener; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); if (listener != null) { listener.onCreate(v, mMapManager); } return v; } }
Then, create a snippet and set onCreateListener. onCreateListener function should update the position of the camera and set the polyline, etc.
When called onLoad on GoogleMap, we need to plan another onLoad, which takes a snapshot (or we again get the wrong tile).
private void onLoad() {
Disadvantage: sometimes the card will flash "false" world map on the screen. To avoid this, we can hide the display of the map as long as the images are made using
mapView.setVisibility(VIEW.INVISIBLE);
It has been tested on google-maps 8.3.0 for Android.