Map Update¶
Setup¶
Prerequisites¶
Build and Run¶
Start a terminal/command prompt and navigate to the map_update
directory within the Flutter examples directory. This is the name of the 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.
Run: flutter pub get
Configure the native parts:
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:
1 allprojects {
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 project pathname
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
orflutter run --release
How it Works¶
This example demonstrates how to simulate an map update. It replaces the default map in the app with the one in the assets, which is an older version and needs to be updated, then applies the logic for updating the map.
Import Necessary Packages¶
First, import the required packages in your Dart code.
1import 'maps_page.dart';
2import 'package:gem_kit/content_store.dart';
3import 'package:gem_kit/core.dart';
4import 'package:gem_kit/map.dart';
5import 'package:map_update/update_persistence.dart';
6import 'package:path/path.dart' as path;
7import 'package:path_provider/path_provider.dart';
8import 'package:flutter/material.dart';
9import 'package:flutter/services.dart';
10import 'dart:io';
Initialize GemKit¶
In the main
function, initialize GemKit with your project API token.
1void main() {
2 const projectApiToken = String.fromEnvironment('GEM_TOKEN');
3
4 GemKit.initialize(appAuthorization: projectApiToken).then((value) {
5 SdkSettings.setAllowConnection(true, onWorldwideRoadMapSupportStatusCallback: (status) {
6 print("UpdatePersistence: onWorldwideRoadMapSupportStatus $status");
7 if (status != Status.upToDate) {
8 UpdatePersistence.instance.isOldData = true;
9 }
10 });
11 SdkSettings.appAuthorization = projectApiToken;
12 });
13
14 runApp(const MyApp());
15}
UI and Map Integration¶
1class MyApp extends StatelessWidget {
2 const MyApp({super.key});
3
4 @override
5 Widget build(BuildContext context) {
6 return const MaterialApp(
7 debugShowCheckedModeBanner: false,
8 title: 'Map Update',
9 home: MyHomePage(),
10 );
11 }
12}
13
14class MyHomePage extends StatefulWidget {
15 const MyHomePage({super.key});
16 @override
17 State<MyHomePage> createState() => _MyHomePageState();
18}
Handle the map update logic and UI¶
Within _MyHomePageState
, define the necessary state variables and methods to interact with the map and manage updates.
}