Human Voices¶
Setup¶
Prerequisites¶
Build and Run¶
Go to the human_voices
directory within the Flutter examples directory. This is the directory name for this example project.
Note - the gem_kit
directory containing the Maps SDK for Flutter
should be in the plugins
directory of the example, e.g.
example_pathname/plugins/gem_kit
- see the environment setup guide above.
Replace example_pathname
with the actual example path name,
such as address_search
Download project dependencies:
flutter upgrade
run the following terminal commands in the project directory,
where the pubspec.yaml
file is located:
flutter clean
flutter pub get
Run the example:
First, verify that the ANDROID_SDK_ROOT
environment variable
is set to the root path of your android SDK.
In android/build.gradle
add the maven {}
block as shown,
within the allprojects {} block
, for both debug and release builds,
without the line numbers, those are for reference:
1allprojects {
2 repositories {
3 google()
4 mavenCentral()
5 maven {
6 url "${rootDir}/../plugins/gem_kit/android/build"
7 }
8 }
9}
in android/app/build.gradle
within the android {}
block, in the defaultConfig {}
block,
the android SDK version minSdk
must be set as shown below.
Additionally, for release builds, in android/app/build.gradle
,
within the android {}
block, add the buildTypes {}
block as shown:
Replace example_pathname
with the actual example pathname, such as center_coordinates
1android {
2 defaultConfig {
3 applicationId "com.magiclane.gem_kit.examples.example_pathname"
4 minSdk 21
5 targetSdk flutter.targetSdk
6 versionCode flutterVersionCode.toInteger()
7 versionName flutterVersionName
8 }
9 buildTypes {
10 release {
11 minifyEnabled false
12 shrinkResources false
13
14 // TODO: Add your own signing config for the release build.
15 // Signing with the debug keys for now, so `flutter run --release` works.
16 signingConfig signingConfigs.debug
17 }
18 }
19}
Then run the project:
flutter run --debug
flutter run --release
In the ios/Podfile
configuration text file, at the top, set the minimum ios
platform to 13 like this:
platform :ios, '13.0'
Then run the project:
flutter run --debug
flutter run --release
How It Works¶
This example integrates several components to simulate navigation with voice instructions. Here’s a breakdown of the key functionalities:
Map Initialization¶
The GemKit SDK is initialized with the necessary API token. The GemMapController is used to manage the map and the displayed routes.
1import 'package:gem_kit/core.dart'; 2import 'package:gem_kit/map.dart'; 3import 'package:gem_kit/navigation.dart'; 4import 'package:gem_kit/routing.dart'; 5 6import 'bottom_navigation_panel.dart'; 7import 'top_navigation_panel.dart'; 8import 'tts_engine.dart'; 9import 'utility.dart'; 10 11import 'package:flutter/material.dart' hide Route; 12 13Future<void> main() async { 14 const projectApiToken = String.fromEnvironment('GEM_TOKEN'); 15 16 await GemKit.initialize(appAuthorization: projectApiToken); 17 runApp(const MyApp()); 18} 19 20class MyApp extends StatelessWidget { 21 const MyApp({super.key}); 22 23 @override 24 Widget build(BuildContext context) { 25 return const MaterialApp( 26 debugShowCheckedModeBanner: false, 27 title: 'Human Voices', 28 home: MyHomePage(), 29 ); 30 } 31}The MaterialApp serves as the root of the application, hosting the MyHomePage widget, where the map and navigation features are implemented.
Route Calculation¶
The user can trigger route calculation, which involves defining landmarks and preferences, then using RoutingService.calculateRoute to compute the route.
1void _onBuildRouteButtonPressed(BuildContext context) { 2 _showSnackBar(context, message: 'The route is calculating.'); 3 4 // Define landmarks. 5 final departureLandmark = 6 Landmark.withLatLng(latitude: 48.87586, longitude: 2.30311); 7 final intermediaryPointLandmark = 8 Landmark.withLatLng(latitude: 48.87422, longitude: 2.29952); 9 final destinationLandmark = 10 Landmark.withLatLng(latitude: 48.87361, longitude: 2.29513); 11 12 // Define the route preferences. 13 final routePreferences = RoutePreferences(); 14 15 // Calculate the route. 16 _routingHandler = RoutingService.calculateRoute( 17 [departureLandmark, intermediaryPointLandmark, destinationLandmark], 18 routePreferences, (err, routes) { 19 _routingHandler = null; 20 ScaffoldMessenger.of(context).clearSnackBars(); 21 22 if (err == GemError.success) { 23 final routesMap = _mapController.preferences.routes; 24 for (final route in routes!) { 25 routesMap.add(route, route == routes.first, 26 label: route.getMapLabel()); 27 } 28 _mapController.centerOnRoutes(routes: routes); 29 setState(() => _areRoutesBuilt = true); 30 } 31 }); 32}
UI Components¶
The example includes custom UI components, such as NavigationInstructionPanel and NavigationBottomPanel, to display navigation instructions and other relevant details during the simulation.
Clean-Up¶
The dispose() method ensures that resources are properly released when the widget is destroyed.
1@override 2void dispose() { 3 GemKit.release(); 4 super.dispose(); 5}