user_location 0.1.3
user_location: ^0.1.3 copied to clipboard
A plugin for FlutterMap to handle and plot the current user location.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:user_location/user_location.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Plugin Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
MapController mapController = MapController();
List<Marker> markers = [];
StreamController<LatLng> markerlocationStream = StreamController();
UserLocationOptions userLocationOptions;
@override
Widget build(BuildContext context) {
//Get the current location of marker
markerlocationStream.stream.listen((onData) {
// print(onData.latitude);
});
userLocationOptions = UserLocationOptions(
context: context,
mapController: mapController,
markers: markers,
onLocationUpdate: (LatLng pos) =>
print("onLocationUpdate ${pos.toString()}"),
updateMapLocationOnPositionChange: false,
showMoveToCurrentLocationFloatingActionButton: true,
zoomToCurrentLocationOnLoad: false,
fabBottom: 50,
fabRight: 50,
verbose: false);
//You can also change the value of updateMapLocationOnPositionChange programatically in runtime.
//userLocationOptions.updateMapLocationOnPositionChange = false;
return Scaffold(
appBar: AppBar(title: Text("Plugin User Location")),
body: FlutterMap(
options: MapOptions(
center: LatLng(27.7172, 85.3240),
zoom: 15.0,
plugins: [
UserLocationPlugin(),
],
),
layers: [
TileLayerOptions(
urlTemplate: "https://api.tiles.mapbox.com/v4/"
"{id}/{z}/{x}/{y}@2x.png?access_token={accessToken}",
additionalOptions: {
'accessToken':
'pk.eyJ1IjoiaWdhdXJhYiIsImEiOiJjazFhOWlkN2QwYzA5M2RyNWFvenYzOTV0In0.lzjuSBZC6LcOy_oRENLKCg',
'id': 'mapbox.streets',
},
),
MarkerLayerOptions(markers: markers),
userLocationOptions
],
mapController: mapController,
),
);
}
void dispose() {
markerlocationStream.close();
}
}
copied to clipboard