parent
b06c895198
commit
52accae66e
@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:smartfit_app_mobile/common/colo_extension.dart';
|
||||
import 'package:smartfit_app_mobile/view/map/mobile/mobile_my_map.dart';
|
||||
import 'package:smartfit_app_mobile/view/map/my_map_osm.dart';
|
||||
|
||||
class ChoseMap extends StatefulWidget {
|
||||
const ChoseMap({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ChoseMap> createState() => _ChoseMap();
|
||||
}
|
||||
|
||||
class _ChoseMap extends State<ChoseMap> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: TColor.white,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const MobileMyMaps()));
|
||||
},
|
||||
child: const Text("Use map with google map")),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (context) => const MyMapOSM()));
|
||||
},
|
||||
child: const Text("Use map with Open Street Map")),
|
||||
const Text(
|
||||
"Mettre une image la en mode une personne avec des jumelles")
|
||||
],
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart' as osm;
|
||||
import 'package:smartfit_app_mobile/common/colo_extension.dart';
|
||||
import 'package:smartfit_app_mobile/modele/user.dart';
|
||||
|
||||
class MyMapOSM extends StatefulWidget {
|
||||
const MyMapOSM({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyMapOSM> createState() => _MyMapOSM();
|
||||
}
|
||||
|
||||
class _MyMapOSM extends State<MyMapOSM> {
|
||||
final controller = MapController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<osm.LatLng> listPolynines =
|
||||
context.watch<User>().managerSelectedActivity.getPositionOSM();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Carte Open Street Map "),
|
||||
backgroundColor: TColor.primaryColor1,
|
||||
),
|
||||
body: FlutterMap(
|
||||
options: MapOptions(center: listPolynines.first),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
),
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
Polyline(
|
||||
points: listPolynines,
|
||||
color: TColor.primaryColor1,
|
||||
strokeWidth: 5.0,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:location/location.dart';
|
||||
|
||||
class MyMap extends StatefulWidget {
|
||||
const MyMap({ Key? key }) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyMap> createState() => _MyMapState();
|
||||
}
|
||||
|
||||
class _MyMapState extends State<MyMap> {
|
||||
|
||||
Completer<GoogleMapController> _googleMapController = Completer();
|
||||
CameraPosition? _cameraPosition;
|
||||
Location? _location;
|
||||
LocationData? _currentLocation;
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() async {
|
||||
_location = Location();
|
||||
_cameraPosition = CameraPosition(
|
||||
target: LatLng(0, 0), // this is just the example lat and lng for initializing
|
||||
zoom: 15
|
||||
);
|
||||
_initLocation();
|
||||
}
|
||||
|
||||
//function to listen when we move position
|
||||
_initLocation() {
|
||||
//use this to go to current location instead
|
||||
_location?.getLocation().then((location) {
|
||||
_currentLocation = location;
|
||||
});
|
||||
_location?.onLocationChanged.listen((newLocation) {
|
||||
_currentLocation = newLocation;
|
||||
moveToPosition(LatLng(_currentLocation?.latitude ?? 0, _currentLocation?.longitude ?? 0));
|
||||
});
|
||||
}
|
||||
|
||||
moveToPosition(LatLng latLng) async {
|
||||
GoogleMapController mapController = await _googleMapController.future;
|
||||
mapController.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: latLng,
|
||||
zoom: 15
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: _buildBody(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return _getMap();
|
||||
}
|
||||
|
||||
Widget _getMarker() {
|
||||
return Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
padding: EdgeInsets.all(2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey,
|
||||
offset: Offset(0,3),
|
||||
spreadRadius: 4,
|
||||
blurRadius: 6
|
||||
)
|
||||
]
|
||||
),
|
||||
child: ClipOval(child: Image.asset("assets/img/u1.png")),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getMap() {
|
||||
return Stack(
|
||||
children: [
|
||||
GoogleMap(
|
||||
initialCameraPosition: _cameraPosition!,
|
||||
mapType: MapType.normal,
|
||||
onMapCreated: (GoogleMapController controller) {
|
||||
// now we need a variable to get the controller of google map
|
||||
if (!_googleMapController.isCompleted) {
|
||||
_googleMapController.complete(controller);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
Positioned.fill(
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: _getMarker()
|
||||
)
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue