Real-time multitype cars location on map. Is it possible with this plugin?
Hi. Thanks you for great package :)
I would like to ask a couple of questions, if you don't mind.
So, before I started I want to mention that I'm new to flutter and may not understand a certain concepts.
So, the thing is I'm trying to get the movement of cars on the map in real time, that is, I want the markers to move across the map in accordance with how the car is moving in real time. I am calling latitude and longitude from my own API because I want cars to appear on the map.
The second thing is I've seen examples with Google Maps for getting realtime transport location and there is a specific function that allows you to update the marker in real time on the map. I have not seen anything like this in OSM map. So inside markerlocationStream.stream.listen((listDir) I am trying put markers and call the long and lat for all markers but nothing works on map. Map shows only my own current location.
So I would like to figure out what am i doing wrong? May be, I don't see the obvious things.
I don't understand what I am doing wrong, although I have been trying to solve the problem for several weeks now. It seems to me that I am missing something obvious and doing something wrong.
As template I am using your file from /example:
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
MapController mapController = MapController();
List<Marker> markers = [];
StreamController<LocVeh> markerlocationStream = StreamController();
UserLocationOptions userLocationOptions;
List<LocVeh> listDir;
onTapFAB() {
userLocationOptions.updateMapLocationOnPositionChange = true;
}
@override
Widget build(BuildContext context) {
//Get the current location of marker
markerlocationStream.stream.listen((listDir) {
return Marker(
point: latLng.LatLng(listDir.uLat, listDir.uLong),
height: 5,
width: 5,
builder: (ctx) => Icon(Icons.my_location_rounded)
);
});
userLocationOptions = UserLocationOptions(
context: context,
mapController: mapController,
markers: markers,
onLocationUpdate: (latLng.LatLng pos) => print("onLocationUpdate ${pos.toString()}"),
updateMapLocationOnPositionChange: true,
showMoveToCurrentLocationFloatingActionButton: true,
zoomToCurrentLocationOnLoad: true,
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.LatLng(48.707103, 44.516939),
zoom: 15.0,
plugins: [
UserLocationPlugin(),
],
),
layers: [
TileLayerOptions(
urlTemplate:
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c']),
MarkerLayerOptions(markers: markers),
userLocationOptions
],
mapController: mapController,
),
);
}
void dispose() {
markerlocationStream.close();
}
}