THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Map snapshot image

The snapshot functionality generates a map image with markers, routes, and shapes that are rendered on the map which you can use as:

  • a screen in another app
  • a notification
  • a social media or communicator message

Sample use case: You would like to take a screenshot of the map with markers, routes, and shapes that are rendered on the map, so you can share this picture in an email, social media, or communicator.

Sample use case: You would like to store the snapshot of the picked place in the storage, so you can display the data with the corresponding snapshot.

Use the following code snippets to take a snapshot of a map:

  • MapFragment
val mapFragment = activity.supportFragmentManager.findFragmentById(R.id.map_fragment) as MapFragment
mapFragment.takeSnapshot(snapshotCallback)
  • MapView
val mapView: MapView = requireActivity().findViewById(R.id.map_view)
mapView.takeSnapshot(snapshotCallback)

Where the snapshotCallback is defined as:

1private val snapshotCallback = object : SnapshotCallback {
2 override fun onSuccess(snapshot: Bitmap) {
3 // The saveSnapshotToCache(snapshot) creates a file in the context.cacheDir, writes bitmap data
4 // into it using snapshot.compress(CompressFormat.JPEG, 100, outputStream) then returns the file.
5 // Before you can obtain URI of this file you need to define a FileProvider in the manifest.
6 val snapshotFile = saveSnapshotToCache(snapshot)
7 snapshotFile?.let {
8 val snapshotUri = FileProvider.getUriForFile(requireContext(), FILE_PROVIDER_AUTHORITY, it)
9
10 val shareIntent = Intent(Intent.ACTION_SEND)
11 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
12 shareIntent.type = "image/jpeg"
13 shareIntent.putExtra(Intent.EXTRA_STREAM, snapshotUri)
14 startActivity(Intent.createChooser(shareIntent, "Send map snapshot"))
15 } ?: run { Toast.makeText(requireContext(), FILE_NOT_FOUND, Toast.LENGTH_SHORT).show() }
16 }
17
18 override fun onError(error: Throwable) {
19 Toast.makeText(requireContext(), error.message, Toast.LENGTH_SHORT).show()
20 }
21}

image

image

image