luckyhandler
luckyhandler

Reputation: 11329

Navigator: Callbacks get never triggered

I'm trying to integrate the HERE SDK for Flutter. I'm using Version 4.3.3.0. I can display my location on the map, I'm also capable of updating the location while moving around but non of the navigator callbacks I registered gets triggered. This is the code for creating the navigator:

void _setupNavigation(NavigationData navigationData) {
  final RouteRepository routeRepository = RepositoryProvider.of<RouteRepository>(context);
  final NavigationBloc navigationBloc = BlocProvider.of<NavigationBloc>(context);

  final here.LocationListener locationListener = _buildLocationListener();
  if (_simulate) {
    _locationSimulator = _buildLocationSimulator(
      navigationData: navigationData,
      locationListener: locationListener,
    );
  }

  _locationProvider = _buildLocationProvider(
    routeRepository: routeRepository,
    locationListener: locationListener,
  );

  _navigator = here.Navigator(_locationProvider);
  _navigator.routeDeviationListener =
      _buildRouteDeviationListener(navigationBloc: navigationBloc);
  _navigator.routeProgressListener =
      _buildRouteProgressListener(navigationBloc: navigationBloc);
  _navigator.navigableLocationListener =
      _buildNavigableLocationListener(navigationBloc: navigationBloc);
  _navigator.maneuverNotificationListener =
      _buildManeuverNotificationListener(navigationBloc: navigationBloc);
  _navigator.maneuverNotificationOptions =
      here.ManeuverNotificationOptions.withDefaults();
  _navigator.route = navigationData.routes?.mainRoute?.route;
  navigationBloc.add(StartNavigation(simulate: _simulate));
}

I create all the listeners according to the same pattern. Here is for example the ManeuverListener:

ManeuverNotificationListener _buildManeuverNotificationListener(
        {@required NavigationBloc navigationBloc}) =>
    here.ManeuverNotificationListener.fromLambdas(
      lambda_onManeuverNotification: (String maneuver) {
        _flutterTts.speak(maneuver);
        navigationBloc.add(NewManeuverNotification(maneuver));
      },
    );

Could please someone point me into the right direction? What is missing to make the callbacks get triggered?

UPDATE This is how I build the LocationProvider:

LocationProvider _buildLocationProvider({
  @required RouteRepository routeRepository,
  @required LocationListener locationListener,
}) {
  StreamSubscription<Location> subscription;
  return here.LocationProvider.fromLambdas(
    lambda_start: () {
      if (!_simulate) {
        subscription =
            routeRepository.locationStream.listen((Location location) {
          locationListener.onLocationUpdated(location.toHereLocation());
        });
      }
    },
    lambda_stop: () => subscription?.cancel(),
    lambda_listener_get: () => locationListener,
    lambda_listener_set: (listener) => {},
  );
 }

Solution

I ended up extending my own class with LocationProvider instead of using the fromLambdas constructor from the LocationProvider class and now it's working. The callbacks are triggered.

Upvotes: 0

Views: 137

Answers (1)

user3505695
user3505695

Reputation:

Feedback received from HERE SDK dev team :)

The locationListener is actually set by the SDK, and your implementation of LocationProviderImplementation is supposed to call the listener, otherwise no guidance will happen.

Please check the Android navigation example as a reference in here, see line#28, and line#101.

Upvotes: 1

Related Questions