Multiview Map¶
Setup¶
Prerequisites¶
Run the example¶
Start a terminal/command prompt and go to the multiview_map
directory,
within the flutter examples directory
Build and run the example:
Build and run¶
Note - the gem_kit
directory containing the Maps SDK for Flutter
should be in the plugins
directory of the example, e.g.
multiview_map/plugins/gem_kit
- see the environment setup guide above.
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:
flutter run
If such a question appears, select the chrome
browser; in the above example, press 2.
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 minSdkVersion
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:
1android {
2 defaultConfig {
3 applicationId "com.magiclane.gem_kit.examples.multiview_map"
4 minSdkVersion 21
5 targetSdkVersion flutter.targetSdkVersion
6 versionCode flutterVersionCode.toInteger()
7 versionName flutterVersionName
8 }
9 buildTypes {
10 release {
11 // TODO: Add your own signing config for the release build.
12 // Signing with the debug keys for now, so `flutter run --release` works.
13 minifyEnabled false
14 shrinkResources false
15 signingConfig signingConfigs.debug
16 }
17 }
18}
Then build the apk:
flutter build apk --debug
flutter build apk --release
build/app/outputs/apk/debug
or
build/app/outputs/apk/release
subdirectory,
for debug or release build respectively,
within the current project directory, which is multiview_map
in this case.app-release.apk
or app-debug.apk
adb push app-release.apk sdcard
And then click on the apk in the file browser on the device to install and run it.
In the ios/Podfile
configuration text file, at the top, set the minimum ios
platform to 13 like this:
platform :ios, '13.0'
pod install
in the [ios folder] ./ios/
flutter build ios
to build a Runner.app.flutter run
to build and run on an attached device.<path/to>/ios/Runner.xcworkspace
project in Xcode
and execute and debug from there.How it works¶
In the multiview_map
project directory, there is a text file named
pubspec.yaml
which contains project configuration and dependencies.
The most important lines from this file are shown here:
1name: multiview_map
2version: 1.0.0+1
3
4environment:
5 sdk: '>=3.0.5 <4.0.0'
6
7dependencies:
8 flutter:
9 sdk: flutter
10 gem_kit:
11 path: plugins/gem_kit
12
13 cupertino_icons: ^1.0.2
14
15# The following section is specific to Flutter packages.
16flutter:
17 uses-material-design: true
The project must have a name and version. The dependencies list the Flutter SDK, and the gem_kit, Maps for Flutter SDK.
The source code is in multiview_map/lib/main.dart
1import 'dart:math';
2
3import 'package:flutter/material.dart';
4import 'package:gem_kit/api/gem_sdksettings.dart';
5import 'package:gem_kit/widget/gem_kit_map.dart';
6
7void main() {
8 runApp(const MultiviewMapApp());
9}
10
11class MultiviewMapApp extends StatelessWidget {
12 const MultiviewMapApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return MaterialApp(
17 title: 'Multiview Map',
18 debugShowCheckedModeBanner: false,
19 theme: ThemeData(
20 colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
21 useMaterial3: true,
22 ),
23 home: const MultiviewMapPage());
24 }
25}
26
27class MultiviewMapPage extends StatefulWidget {
28 const MultiviewMapPage({super.key});
29
30 @override
31 State<MultiviewMapPage> createState() => _MultiviewMapPageState();
32}
The dart
material package is imported, as well as the gem_kit
packages for the map to draw the maps, and the sdk settings.
The map is in a widget which is the root of the application.
1class _MultiviewMapPageState extends State<MultiviewMapPage> {
2 int _mapViewsCount = 0;
3 final token = 'YOUR_API_KEY_TOKEN';
4
5 @override
6 Widget build(BuildContext context) {
7 return Scaffold(
8 appBar: AppBar(
9 backgroundColor: Colors.deepPurple[900],
10 title: const Text('Multiview Map',
11 style: TextStyle(color: Colors.white)),
12 actions: [
13 IconButton(
14 onPressed: _onAddViewButtonPressed,
15 icon: const Icon(
16 Icons.add,
17 color: Colors.white,
18 )),
19 IconButton(
20 onPressed: _onRemoveViewButtonPressed,
21 icon: const Icon(
22 Icons.remove,
23 color: Colors.white,
24 ))
25 ],
26 ),
27 // Arrange MapViews in a grid with fixed number on elements on row
28 body: GridView.builder(
29 physics: const NeverScrollableScrollPhysics(),
30 gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
31 crossAxisCount: 2),
32 itemCount: _mapViewsCount,
33 itemBuilder: (context, index) {
34 return Container(
35 clipBehavior: Clip.hardEdge,
36 decoration: BoxDecoration(
37 border: Border.all(color: Colors.black, width: 1),
38 borderRadius: BorderRadius.circular(10),
39 boxShadow: const [
40 BoxShadow(
41 color: Colors.grey,
42 offset: Offset(0, -2),
43 spreadRadius: 1,
44 blurRadius: 2)
45 ]),
46 margin: const EdgeInsets.all(5),
47 child: GemMap(
48 onMapCreated: (controller) async {
49 final settings =
50 await SdkSettings.create(controller.mapId);
51 await settings.setAppAuthorization(token);
52 },
53 ));
54 }));
55 }
56
57 // Add one more view on button press
58 _onAddViewButtonPressed() => setState(() {
59 if (_mapViewsCount < 4) {
60 _mapViewsCount += 1;
61 }
62 });
63 _onRemoveViewButtonPressed() => setState(() {
64 if (_mapViewsCount > 0) {
65 _mapViewsCount -= 1;
66 }
67 });
68}
An empty grid is initialized, and an interactive map is added
each time the _onAddViewButtonPressed()
+ (plus) button
at the top right is pressed, up to 4 maps.
The most recently added map can be removed
using the _onRemoveViewButtonPressed()
- (minus) button
at the top right.
Setting the API key¶
The string |