I tried to make the Google Map move between all the markers on the map and make a screenshot of this map section. For the test did so, but of course it does not work as it should:

button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { for (int i = 0; i < markers.size(); i++) { CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(markers.get(i).getLatitude(), markers.get(i).getLongitude())) .zoom(15).build(); mGoogleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() { Bitmap bitmap; @Override public void onSnapshotReady(Bitmap snapshot) { bitmap = snapshot; try { String time = String.valueOf(System.currentTimeMillis()); FileOutputStream out = new FileOutputStream("/mnt/sdcard/Android/data/com.app.my/files/" + time + ".png"); //just for test bitmap.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { Log.e(LogTag.MY_FILTER_ERROR, "Screenshot error", e); } } }; mGoogleMap.snapshot(callback); } } }); 

This code makes the required number of screenshots, but the map does not have time to move between the markers and be loaded. I understand that it should work in a separate thread, please suggest how best to do it.

    1 answer 1

    In general, if anyone is interested, he did this:

     public void uploadScreenshots() { if (getRootActivity() != null) { iterator = 0; map =... sortedKeys =... //перемещение к первому маркеру CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(map.get(sortedKeys.get(iterator)).getLatitude(), map.get(sortedKeys.get(iterator)).getLongitude())) .zoom(15).build(); mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 1, new GoogleMap.CancelableCallback() { @Override public void onFinish() { iterator++; mGoogleMap.setOnMapLoadedCallback(new CallBackLoadMap()); } @Override public void onCancel() { } }); //далее рекурсивно обходим остальные маркеры mGoogleMap.setOnMapLoadedCallback(new CallBackLoadMap()); } } class CallBackLoadMap implements GoogleMap.OnMapLoadedCallback { @Override public void onMapLoaded() { final GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() { Bitmap bitmap; @Override public void onSnapshotReady(Bitmap snapshot) { bitmap = snapshot; try { String time = String.valueOf(System.currentTimeMillis()); FileOutputStream out = new FileOutputStream("/mnt/sdcard/Android/data/com.app.my/files/" + time + ".png"); //просто для теста - хардкодить плохо! bitmap.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { Log.e(LogTag.MY_FILTER_ERROR, "Screenshot error", e); } } }; mGoogleMap.snapshot(callback); if (iterator == sortedKeys.size()) return; CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(map.get(sortedKeys.get(iterator)).getLatitude(), map.get(sortedKeys.get(iterator)).getLongitude())) .zoom(15).build(); mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 1, new GoogleMap.CancelableCallback() { @Override public void onFinish() { iterator++; mGoogleMap.setOnMapLoadedCallback(new CallBackLoadMap()); } @Override public void onCancel() { } }); } } 

    It works as it should - the transition between all the markers and the creation of a screenshot after the map is fully loaded in this place.