Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Mapping package for Flutter, based off of 'leaflet.js'. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
@override
Widget build(BuildContext context) {
return FlutterMap(
options: MapOptions(
center: LatLng(51.509364, -0.128928),
zoom: 9.2,
),
nonRotatedChildren: [
RichAttributionWidget(
attributions: [
TextSourceAttribution(
'OpenStreetMap contributors',
onTap: () => launchUrl(Uri.parse('https://openstreetmap.org/copyright')),
),
],
),
],
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
),
],
);
}FlutterMap, containing a Marker, Polyline, Polygon, and RichAttributionLayer on top of a TileLayer
class CustomLayer extends StatelessWidget {
const CustomLayer({super.key});
@override
Widget build(BuildContext context) {
final mapState = FlutterMapState.of(context);
// Use `mapState` as necessary, for example `mapState.zoom`
}
}flutter pub add flutter_map
flutter pub add latlong2dependency_overrides:
flutter_map:
git:
url: https://github.com/fleaflet/flutter_map.git
# ref: main (custom branch/commit)<uses-permission android:name="android.permission.INTERNET"/><key>com.apple.security.network.client</key>
<true/>import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/plugin_api.dart'; // Only import if required functionality is not exposed by defaultFlutterMap(
mapController: _mapController,
options: MapOptions(),
children: [],
nonRotatedChildren: [],
);PolygonLayer(
polygons: [
Polygon(
points: [LatLng(30, 40), LatLng(20, 50), LatLng(25, 45)],
color: Colors.blue,
isFilled: true,
),
],
),
PolygonCircleLayer(
circles: [
CircleMarker(
point: LatLng(51.50739215592943, -0.127709825533512),
radius: 10000,
useRadiusInMeter: true,
),
],
),
CircleMarkerTileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),userAgentPackageNameRotatedOverlayImageOverlayImageLayer(
circles: [
OverlayImage(
bounds: LatLngBounds(
LatLng(45.3367881884556, 14.159452282322459),
LatLng(45.264129635422826, 14.252585831779033),
),
imageProvider: NetworkImage(),
),
],
),
RichAttributionWidget
RichAttributionWidget, as in the example app
SimpleAttributionWidget, as in the example appclass CustomTileProvider extends TileProvider {
// Add your own custom properties, methods, etc.
CustomTileProvider({
// Suitably initialise your own custom properties
super.headers, // Use the Dart 2.17 `super` syntax to initialise the base's header `Map`
})
} @override
ImageProvider getImage(Coords<num> coords, TileLayerOptions options) =>
CustomImageProvider(
options: options,
coords: coords,
headers: {
...headers,
'User-Agent': headers['User-Agent'] == null
? '<pluginName> for flutter_map (unknown)'
: '<pluginName> for ${headers['User-Agent']}',
},
); @override
String getTileUrl(Coords coords, TileLayerOptions options) {
// Custom generation
}nonRotatedChildren: [
RichAttributionWidget(
animationConfig: const ScaleRAWA(), // Or `FadeRAWA` as is default
attributions: [
TextSourceAttribution(
'OpenStreetMap contributors',
onTap: () => launchUrl(Uri.parse('https://openstreetmap.org/copyright')),
),
],
),
],nonRotatedChildren: [
SimpleAttributionWidget(
source: Text('OpenStreetMap contributors'),
),
],options: MapOptions(
interactiveFlags: ~InteractiveFlag.doubleTapZoom,
),pointsPolylineLayer(
polylines: [
Polyline(
points: [LatLng(30, 40), LatLng(20, 50), LatLng(25, 45)],
color: Colors.blue,
),
],
),
Polylineimport 'package:latlong2/latlong.dart';
export 'package:google_polyline_algorithm/google_polyline_algorithm.dart'
show decodePolyline;
extension PolylineExt on List<List<num>> {
List<LatLng> unpackPolyline() =>
map((p) => LatLng(p[0].toDouble(), p[1].toDouble())).toList();
}import '<code_snippet_path>'
decodePolyline('<encoded-polyline>').unpackPolyline(); // Returns `List<LatLng>` for a map polyline

MapOptions contains an onMapReady callback (see Event Handling) is called once when the map is initialised, and the initialised map controller can be used freely within it.final mapController = MapController();
@override
Widget build(BuildContext context) =>
FlutterMap(
mapController: mapController,
...
);final mapController = MapController();
@override
Widget build(BuildContext context) =>
FlutterMap(
mapController: mapController,
options: MapOptions(
onMapReady: () {
mapController.mapEventStream.listen((evt) {});
// And any other `MapController` dependent non-movement methods
},
),
);Unexpected error with integration github-files: Integration is not installed on this space