I'm writing a app that would take 9 snapshots of the map around an area when the user presses a button.
In loop, using this to move and save:
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mStartLat + (mMultiOffsetX + mWidth), mStartLng + (mMultiOffsetY + mHeight)), mZoom));
map.snapshot(this);
and in onSnapshotReady:
final String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + String.format("/test_maps/map_%f_%f.png", Double.valueOf(mStartLat + (mMultiOffsetX * mWidth)), Double.valueOf(mStartLng + (mMultiOffsetY * mHeight)));
FileOutputStream fos = new FileOutputStream(new File(fileName));
bmp.compress(CompressFormat.PNG, 0, fos);
Unfortunately the map occasionally finished loading when the snapshot is taken, so you end up with:
So, is there any way to detect or set a listener for when the map view has finished loading?
OnMapLoadedCallback doesn't fire until after the tiles on map are loaded. Only fires once so you'll have to call it nine times to take nine snapshots.
When you have a reference to the map set the call back.
mMap.setOnMapLoadedCallback(this);
When the onMapLoaded event fires take the snapshot.
@Override
public void onMapLoaded() {
if (mMap != null) {
mMap.snapshot(this);
}
}
See the documentation for further information: https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.OnMapLoadedCallback
Good Luck
**** history of waiting for this feature to be implemented.
Updates: Status: Fixed Labels: Fixed-Oct2013
Comment #3 on issue 5779 by [email protected]: Ability to be notified when the map is fully loaded/rendered http://code.google.com/p/gmaps-api-issues/issues/detail?id=5779
A map loaded callback interface has been added in the latest release of the Google Maps Android API v2.
See the documentation for further information: https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.OnMapLoadedCallback
Thanks to everyone for starring issue 5779 and 61675 Danny117
**** edit ****
Please star this issue if you come here. http://code.google.com/p/android/issues/detail?id=61675 Your star clicks will motivate google to move on this issue.
The map update 13 causes a problem with google play services so you can't use the new OnMapLoadedCallback yet. You can compile against it but the map api generates an error message in the logcat Google Play services out of date. Requires 4030500 but found 3266130
* edit * Brand new OnMapLoadedCallback
Updates: Status: Fixed Labels: Fixed-Oct2013
Comment #3 on issue 5779 by [email protected]: Ability to be notified when the map is fully loaded/rendered http://code.google.com/p/gmaps-api-issues/issues/detail?id=5779
A map loaded callback interface has been added in the latest release of the Google Maps Android API v2.
See the documentation for further information: https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.OnMapLoadedCallback
Thanks to everyone for starring issue 5779. Danny117
**** The following is deprecated *****
Looks like its a wait for update solution. I clicked the star for you as I was going to work on this feature in my own api v2 map.
edit*** This is the proposed new callback for when the map is rendered. Everyone that visits please follow link and star this issue. http://code.google.com/p/gmaps-api-issues/issues/detail?id=5779
*** previous snapshop callback will not be changed. Everyone that visits please follow link and star this issue. http://code.google.com/p/gmaps-api-issues/issues/detail?id=5712
https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.SnapshotReadyCallback
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With