2021-09-29 10:07:56 +02:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:math';
|
|
|
|
|
2021-09-28 08:18:14 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
import 'package:google_track_trace/google_track_trace.dart';
|
|
|
|
|
|
|
|
class TrackTraceDemo extends StatefulWidget {
|
2021-09-28 10:37:48 +02:00
|
|
|
const TrackTraceDemo({Key? key}) : super(key: key);
|
|
|
|
|
2021-09-28 08:18:14 +02:00
|
|
|
@override
|
|
|
|
State<TrackTraceDemo> createState() => _TrackTraceDemoState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TrackTraceDemoState extends State<TrackTraceDemo> {
|
2021-09-29 10:07:56 +02:00
|
|
|
TrackTraceController? controller;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
|
|
Timer.periodic(const Duration(seconds: 10), (_) {
|
|
|
|
print('updating marker');
|
|
|
|
getRandomPointOnMap();
|
|
|
|
});
|
|
|
|
|
|
|
|
Timer.periodic(const Duration(seconds: 60), (_) {
|
|
|
|
print('updating route');
|
|
|
|
getRandomRoute();
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2021-09-28 08:18:14 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2021-09-29 10:07:56 +02:00
|
|
|
appBar: AppBar(
|
|
|
|
title: (controller == null)
|
|
|
|
? const Text('TrackTrace example')
|
|
|
|
: Text(controller!.duration.toString() + ' seconds')),
|
2021-09-28 08:18:14 +02:00
|
|
|
body: GoogleTrackTraceMap(
|
|
|
|
startPosition: const Marker(
|
|
|
|
markerId: MarkerId('Start locatie'),
|
|
|
|
position: LatLng(51.965578, 6.293439),
|
|
|
|
),
|
|
|
|
destinationPosition: const Marker(
|
|
|
|
markerId: MarkerId('Eind locatie'),
|
|
|
|
position: LatLng(51.958996, 6.296520),
|
|
|
|
),
|
2021-09-29 10:07:56 +02:00
|
|
|
googleAPIKey: 'AIzaSyDaxZX8TeQeVf5tW-D6A66WLl20arbWV6c',
|
|
|
|
travelMode: TravelMode.walking,
|
|
|
|
routeUpdateInterval: 60,
|
|
|
|
routeLabel: 'Test route',
|
|
|
|
timerPrecision: TimePrecision.everySecond,
|
|
|
|
zoomGesturesEnabled: true,
|
|
|
|
onMapCreated: (ctr) => {
|
|
|
|
controller = ctr,
|
|
|
|
ctr.addListener(() {
|
|
|
|
setState(() {});
|
|
|
|
}),
|
|
|
|
},
|
2021-09-28 08:18:14 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-09-29 10:07:56 +02:00
|
|
|
|
|
|
|
void updateMap() {
|
|
|
|
controller!.current = const Marker(
|
|
|
|
markerId: MarkerId('Huidige locatie'),
|
|
|
|
position: LatLng(51.962578, 6.294439),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void getRandomPointOnMap() {
|
|
|
|
// 51.989909, 6.234950
|
|
|
|
|
|
|
|
// 51.939909, 6.314950
|
|
|
|
if (controller != null) {
|
|
|
|
controller!.current = Marker(
|
|
|
|
markerId: MarkerId('Huidige Locatie'),
|
|
|
|
position: LatLng(51.93 + Random().nextDouble() * 0.06,
|
|
|
|
6.23 + Random().nextDouble() * 0.08));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void getRandomRoute() {
|
|
|
|
// if (route != null) {
|
|
|
|
// print('removing point');
|
|
|
|
// PointLatLng point = route!.polylinePoints[1];
|
|
|
|
// trackTraceController.startMarker = Marker(
|
|
|
|
// markerId: MarkerId('Start locatie'),
|
|
|
|
// position: LatLng(point.latitude, point.longitude));
|
|
|
|
// }
|
|
|
|
if (controller != null) {
|
|
|
|
controller!.start = Marker(
|
|
|
|
markerId: MarkerId('Start Locatie'),
|
|
|
|
position: LatLng(51.93 + Random().nextDouble() * 0.06,
|
|
|
|
6.23 + Random().nextDouble() * 0.08));
|
|
|
|
controller!.end = Marker(
|
|
|
|
markerId: MarkerId('Bestemming Locatie'),
|
|
|
|
position: LatLng(51.93 + Random().nextDouble() * 0.06,
|
|
|
|
6.23 + Random().nextDouble() * 0.08));
|
|
|
|
}
|
|
|
|
}
|
2021-09-28 08:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2021-09-29 10:07:56 +02:00
|
|
|
runApp(const MaterialApp(home: TrackTraceDemo()));
|
2021-09-28 08:18:14 +02:00
|
|
|
}
|