Last active
November 20, 2020 15:12
-
-
Save dariadobsai/09258c013bd42bb28e8f037e119751c6 to your computer and use it in GitHub Desktop.
MapBox in Flutter Part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_map/flutter_map.dart'; | |
import 'package:latlong/latlong.dart'; | |
import 'package:user_location/user_location.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
MapController mapController = MapController(); | |
UserLocationOptions userLocationOptions; | |
List<Marker> markers = []; | |
@override | |
Widget build(BuildContext context) { | |
userLocationOptions = UserLocationOptions( | |
context: context, | |
mapController: mapController, | |
zoomToCurrentLocationOnLoad: false, | |
updateMapLocationOnPositionChange: false, | |
showMoveToCurrentLocationFloatingActionButton: true, | |
markers: markers, | |
); | |
return Scaffold( | |
body: FlutterMap( | |
mapController: mapController, | |
options: MapOptions( | |
center: LatLng(51.5074, 0.1278), | |
zoom: 16.0, | |
minZoom: 10, | |
plugins: [ | |
UserLocationPlugin(), | |
], | |
), | |
layers: [ | |
new TileLayerOptions( | |
urlTemplate: | |
'https://api.mapbox.com/styles/v1/{user}/{style}/tiles/256/{z}/{x}/{y}@2x?access_token={accessToken}', | |
additionalOptions: { | |
'accessToken': 'YOUR accessToken', | |
}, | |
), | |
userLocationOptions, | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment