Camera Feed
This example demonstrates how to build a Flutter app using the Maps SDK to display a live camera feed (while recording) and overlay it on the map.
How It Works
The example app highlights the following features:
- Initializing the GemKit SDK.
- Requesting and handling camera, microphone, and location permissions.
- Starting and stopping video recording with the device’s camera.
- Streaming the live camera frames to a
GemCameraPlayer
widget. - Overlaying the camera preview on top of the map.
- Properly disposing of resources when recording stops or the app is closed.
UI and Map Integration
The following code builds the UI with a GemMap
widget and an app bar that includes buttons for starting/stopping recording and streaming the camera feed.
Requesting Location Permission
Before streaming or recording, the app requests camera, microphone, and location permissions:
Starting Recording and Camera Feed
Tapping the Play button initializes the live data source, starts recording, and sets up the GemCameraPlayerController
to stream frames:
Stopping Recording and Disposing Resources
Tapping the Stop button stops the recorder, disposes the player, and stops the data source:
Stopping Recording and Disposing Resources
A small, resizable preview of the camera feed is overlaid in the top-left corner using GemCameraPlayer
:
Utility Functions
The getDirectoryPath
function retrieves the root directory path for the app and returns the desired directory path inside the "Data" folder.
- Android
- iOS
Add the following code to the android/app/src/main/AndroidManifest.xml
file, within the <manifest>
block:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
This example uses the Permission Handler package. Be sure to follow the setup guide.
Add the following to ios/Runner/Info.plist
inside the <dict>
:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location is needed for map localization and navigation</string>
<key>NSCameraUsageDescription</key>
<string>Camera access is needed for video recording</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need microphone access to record audio.</string>
This example uses the Permission Handler package. Follow the official setup instructions. Add this to your ios/Podfile
:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
'PERMISSION_LOCATION=1',
'PERMISSION_CAMERA=1',
'PERMISSION_MICROPHONE=1'
]
end
end
end