flutter_mapbox_navigation icon indicating copy to clipboard operation
flutter_mapbox_navigation copied to clipboard

Route is not being created but the users location is being

Open manandharsudhir opened this issue 3 years ago • 3 comments

I am using android sdk version 33 and the mapbox navigation is creating the map but there is no route being created.

here is my code `import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_mapbox_navigation/flutter_mapbox_navigation.dart'; import 'package:mapbox_gl/mapbox_gl.dart';

class TurnByTurn extends StatefulWidget { const TurnByTurn({Key? key}) : super(key: key);

@override State<TurnByTurn> createState() => _TurnByTurnState(); }

class _TurnByTurnState extends State<TurnByTurn> { // Waypoints to mark trip start and end // final _origin = WayPoint( // name: "Way Point 1", // latitude: 27.747837, // longitude: 85.305898); // final _stop1 = WayPoint( // name: "Way Point 2", // latitude: 38.91113678979344, // longitude: -77.03847169876099); // final _stop2 = WayPoint( // name: "Way Point 3", // latitude: 38.91040213277608, // longitude: -77.03848242759705); // final _stop3 = WayPoint( // name: "Way Point 4", // latitude: 38.909650771013034, // longitude: -77.03850388526917); // final _destination = WayPoint( // name: "Way Point 5", // latitude: 38.90894949285854, // longitude: -77.03651905059814);

final _home = WayPoint(name: "Home", latitude: 27.6771826, longitude: 85.3177465);

final _store = WayPoint(name: "Store", latitude: 27.6767664, longitude: 85.3191614); late WayPoint sourceWaypoint, destinationWaypoint; var wayPoints = <WayPoint>[];

// Config variables for Mapbox Navigation late MapBoxNavigation directions; late MapBoxOptions _options; late double distanceRemaining, durationRemaining; late MapBoxNavigationViewController _controller; final bool isMultipleStop = false; String instruction = ""; bool arrived = false; bool routeBuilt = false; bool isNavigating = false;

@override void initState() { super.initState(); initialize(); }

Future initialize() async { // If the widget was removed from the tree while the asynchronous platform // message was in flight, we want to discard the reply rather than calling // setState to update our non-existent appearance. if (!mounted) return;

directions = MapBoxNavigation(onRouteEvent: _onRouteEvent);
_options = MapBoxOptions(
    //initialLatitude: 36.1175275,
    //initialLongitude: -115.1839524,
    zoom: 15.0,
    tilt: 0.0,
    bearing: 0.0,
    enableRefresh: false,
    alternatives: true,
    enableFreeDriveMode: false,
    voiceInstructionsEnabled: true,
    bannerInstructionsEnabled: true,
    allowsUTurnAtWayPoints: true,
    mode: MapBoxNavigationMode.drivingWithTraffic,
    units: VoiceUnits.imperial,
    simulateRoute: false,
    animateBuildRoute: true,
    longPressDestinationEnabled: true,
    language: "en");

String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
  platformVersion = await directions.platformVersion;
} on PlatformException {
  platformVersion = 'Failed to get platform version.';
}

setState(() {
  platformVersion = platformVersion;
});

}

@override Widget build(BuildContext context) { return Scaffold( floatingActionButton: FloatingActionButton( onPressed: () async { var wayPoints = <WayPoint>[]; wayPoints.add(_home); wayPoints.add(_store); print(wayPoints);

        await directions.startNavigation(
            wayPoints: wayPoints, options: _options);
      },
      child: Text("Start")),
);

}

Future _onRouteEvent(e) async { print(e); switch (e.eventType) { case MapBoxEvent.progress_change: var progressEvent = e.data as RouteProgressEvent; arrived = progressEvent.arrived!; if (progressEvent.currentStepInstruction != null) { instruction = progressEvent.currentStepInstruction!; } break; case MapBoxEvent.route_building: case MapBoxEvent.route_built: routeBuilt = true; break; case MapBoxEvent.route_build_failed: routeBuilt = false; break; case MapBoxEvent.navigation_running: isNavigating = true; break; case MapBoxEvent.on_arrival: arrived = true; if (!isMultipleStop) { await Future.delayed(const Duration(seconds: 3)); await _controller.finishNavigation(); } else {} break; case MapBoxEvent.navigation_finished: case MapBoxEvent.navigation_cancelled: routeBuilt = false; isNavigating = false; break; default: break; } //refresh UI setState(() {}); } } `

manandharsudhir avatar Aug 03 '22 10:08 manandharsudhir

I have the same issue

a-ahmed116 avatar Sep 10 '22 07:09 a-ahmed116

same here

fpollakowsky avatar Sep 12 '22 16:09 fpollakowsky

Got the same issue, any update yet?

LukasDieth avatar Sep 12 '22 16:09 LukasDieth

got the same issue waiting for update

santosh81066 avatar Sep 23 '22 17:09 santosh81066

Hi, Got the same issue, have anybody find a solution?

Adosio14 avatar Mar 09 '23 15:03 Adosio14

Any solution ?

k-achraf avatar Mar 15 '23 21:03 k-achraf

Stale issue message

eopeter avatar May 23 '23 01:05 eopeter