private void takeSnapshot() { if (mMap == null) { return; } final ImageView snapshotHolder = (ImageView) findViewById(R.id.snapshot_holder); final SnapshotReadyCallback callback = new SnapshotReadyCallback() { @Override public void onSnapshotReady(Bitmap snapshot) { // Callback is called from the main thread, so we can modify the ImageView safely. snapshotHolder.setImageBitmap(snapshot); } }; if (mWaitForMapLoadCheckBox.isChecked()) { mMap.setOnMapLoadedCallback(new OnMapLoadedCallback() { @Override public void onMapLoaded() { mMap.snapshot(callback); } }); } else { mMap.snapshot(callback); } }
@Override public void setOnMapLoadedCallback(OnMapLoadedCallback callback) { map.setOnMapLoadedCallback(callback); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.select_location_activity); // Set up map GoogleMap map = getMap(); map.setOnMapClickListener(new LocationSelectedListener()); map.setOnMapLoadedCallback(new OnMapLoadedCallback() { @Override public void onMapLoaded() { String msg = getString(R.string.select_location_tap_to_select_location); Toast.makeText(SelectLocationActivity.this, msg, Toast.LENGTH_LONG).show(); } }); UiSettings settings = map.getUiSettings(); settings.setMapToolbarEnabled(false); settings.setZoomControlsEnabled(true); settings.setZoomGesturesEnabled(true); settings.setScrollGesturesEnabled(true); // Get bundle data Bundle bundle = getIntent().getExtras(); if (bundle != null) { Double startLat = bundle.getDouble(START_LAT, Double.NaN); Double startLng = bundle.getDouble(START_LNG, Double.NaN); // Zoom in to and mark the current position if (!startLat.isNaN() && !startLng.isNaN()) { LatLng position = new LatLng(startLat, startLng); map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, zoomLevel)); map.addMarker(new MarkerOptions() .position(position)); } } }