You are not logged in.


*** NOTICE: By 30th of September 2022 the will be retired, please request a category for your community in the new ones as soon as possible using this process, which will allow you to propose your community moderators. We expect the migration of data will be finished by that date, you can follow its progress here.***

#1 2021-01-22 10:16:00

Registered: 2020-12-31
Posts: 3

How to track vehicle traffic in real time on the OSMmap using the loca

I'm trying to create an application that tracking the movement of vehicles, so I first plotted stop icons on the map, and now I want the vehicle movement to be displayed on the map. I found a location_package with which I can do this. Also, since I use OSM maps , it is flutter_map package(I saw a solution for google maps, but I need to use free maps), then I need to display the traffic on it and I don't understand where to give the code that I wrote below.

Also I wanted not just animate this markers but take the real live movement.

Maybe I need to use a different package to solve my issues?

Also I take all longitude and latitude from my own API and the code ise down bellow.

Now i am using this code below to display the all icons of moving transport but it dosen't work and I am confused.

Can you guys give me a hint what I am missingin this project?

the code

class TransportMove extends StatefulWidget {
  _TransportMoveState createState() => _TransportMoveState();

class _TransportMoveState extends State<TransportMove> {
  List<LocVeh> listDir;
  Future <List<LocVeh>> futureMove;
  List<Marker> allMarkers = [];


  void initState() {
    futureMove = fetchLoc();

  Widget build(BuildContext context) {
    return FutureBuilder<List<LocVeh>>(
      future: futureMove,
        builder: (context, snapshot){
        }else if(snapshot.hasError){
          listDir =;
          listDir.forEach((element) {
            allMarkers = => Marker(
              point: latLng.LatLng(e.uLong, e.uLat),
                  width: 10,
              height: 10,
                builder: (ctx) => Icon(Icons.directions_car, color:,)
            )).toList(growable: true);
          return Text("${snapshot.error}");
        }return CircularProgressIndicator();

class LocationTraking {
  LocVeh _currentLocation;

  StreamController<LocVeh> _locationController = StreamController<LocVeh>();

  Stream<LocVeh> get locationStream =>;

  LocationService() {
    // Request permission to use location
    location.requestPermission().then((granted) {
      if (granted != null) {
        // If granted listen to the onLocationChanged stream and emit over our controller
        location.onLocationChanged.listen((locationData) {
          if (locationData != null) {
              uLat: locationData.latitude,
              uLong: locationData.longitude,

  var location = Location();

  Future<LocVeh> getLocation() async {
    try {
      var userLocation = await location.getLocation();
      _currentLocation = LocVeh(
        uLat: userLocation.latitude,
        uLong: userLocation.longitude,
    } on Exception catch (e) {
      print('not work');
    return _currentLocation;
the API with long and lat which I give to transport on flutter map

class LocVeh {

  int srvId;
  int ttId;
  String uModel;
  DateTime uTimenav;
  double uLat;
  double uLong;
  int uSpeed;
  int uCourse;

  factory LocVeh.fromJson(Map<String, dynamic> json) => LocVeh(
    srvId: json["srv_id"],

    ttId: json["tt_id"],
    uTimenav: DateTime.parse(json["u_timenav"]),
    uLat: json["u_lat"].toDouble(),
    uLong: json["u_long"].toDouble(),
    uSpeed: json["u_speed"],
    uCourse: json["u_course"],

  Map<String, dynamic> toJson() => {
    "srv_id": srvId,
    "tt_id": ttId,
    "u_model": uModel,
    "u_timenav": uTimenav.toIso8601String(),
    "u_lat": uLat,
    "u_long": uLong,
    "u_speed": uSpeed,
    "u_course": uCourse,

Last edited by annahernandez99 (2021-01-23 09:33:02)


#2 2021-10-10 09:32:59

Abdulrahman Alhatti
New Member
Registered: 2021-10-10
Posts: 1

Re: How to track vehicle traffic in real time on the OSMmap using the loca

please if you solved the problem tell me, i faced the same problem


#3 2021-10-11 20:21:02

Registered: 2021-09-12
Posts: 8

Re: How to track vehicle traffic in real time on the OSMmap using the loca

Please remove the link to since it does not contain anything related to the question.


Board footer

Powered by FluxBB