Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87a8283

Browse files
tomwyrtobrun
authored andcommitted
Describe Mapbox setup in new Flutter project
1 parent f682350 commit 87a8283

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,49 @@ embedded interactive and customizable vector maps inside of a Flutter widget. Th
1111

1212
### Android
1313

14-
This demo app uses Mapbox vector tiles, which require a Mapbox account and a Mapbox access token. Obtain a free access token on [your Mapbox account page](https://www.mapbox.com/account/access-tokens/).
14+
Following examples use Mapbox vector tiles, which require a Mapbox account and a Mapbox access token. Obtain a free access token on [your Mapbox account page](https://www.mapbox.com/account/access-tokens/). After you get the key, place it in project's Android directory:
15+
- Create a `local.properties` file with the following path: `$project_dir/android/local.properties`
16+
- Add `mapbox.accessToken="YOUR MAPBOX ACCESS TOKEN"`
17+
token to the **local.properties** file.
18+
19+
#### Demo app
1520

1621
- Install [Flutter](https://flutter.io/get-started/) and validate its installation with `flutter doctor`
1722
- Clone this repository with `git clone [email protected]:mapbox/flutter-mapbox-gl.git`
18-
- Create a `local.properties` file with the following path: `flutter_mapbox/example/android/local.properties`
19-
- Add `mapbox.accessToken="YOUR MAPBOX ACCESS TOKEN"`
20-
token to the **local.properties** file.
2123
- Run the app with `cd flutter_mapbox/example && flutter run`
2224

25+
#### New project
26+
27+
- Create new Flutter project in your IDE or via terminal
28+
- Add `mapbox_gl: ^0.0.1` dependency to `pubspec.yaml` file and [get the package](https://flutter.io/using-packages/#adding-a-package-dependency-to-an-app)
29+
- Add Mapbox dependency and read token value in Android module `build.gradle` file:
30+
```
31+
android {
32+
defaultConfig {
33+
// ...
34+
def mapboxAccessToken = localProperties.getProperty('mapbox.accessToken')
35+
buildConfigField "String", "MAPBOX_ACCESS_TOKEN", "$mapboxAccessToken"
36+
}
37+
}
38+
39+
dependencies {
40+
// ...
41+
implementation "com.mapbox.mapboxsdk:mapbox-android-sdk:6.1.0-SNAPSHOT"
42+
}
43+
```
44+
- Initialize Mapbox in Android `MainActivity` class:
45+
```
46+
override fun onCreate(savedInstanceState: Bundle?) {
47+
// ...
48+
Mapbox.getInstance(this, BuildConfig.MAPBOX_ACCESS_TOKEN)
49+
}
50+
```
51+
- Import Mapbox widgets and add them to your widget tree
52+
```
53+
import 'package:mapbox_gl/controller.dart';
54+
import 'package:mapbox_gl/flutter_mapbox.dart';
55+
import 'package:mapbox_gl/overlay.dart';
56+
```
2357

2458
## Documentation
2559

@@ -39,4 +73,4 @@ This README file currently houses all of the documentation for this Flutter proj
3973

4074
We welcome contributions to this repository!
4175

42-
If you're interested in helping build this Mapbox/Flutter integration, please read [the contribution guide](https://github.com/mapbox/flutter-mapbox-gl/blob/master/CONTRIBUTING.md) to learn how to get started.
76+
If you're interested in helping build this Mapbox/Flutter integration, please read [the contribution guide](https://github.com/mapbox/flutter-mapbox-gl/blob/master/CONTRIBUTING.md) to learn how to get started.

0 commit comments

Comments
 (0)