Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puck layer not added the same way on iOS and Android #577

Open
basvdijk opened this issue Jun 11, 2024 · 4 comments
Open

Puck layer not added the same way on iOS and Android #577

basvdijk opened this issue Jun 11, 2024 · 4 comments

Comments

@basvdijk
Copy link

When you set the puck settings as:

    mapboxMap?.location.updateSettings(
      LocationComponentSettings(
        pulsingEnabled: false,
        showAccuracyRing: true,
        puckBearing: PuckBearing.COURSE,
        puckBearingEnabled: true,
      ),
    );

You can access the puck layer with:

if (Platform.isAndroid) {
      puckLayerId = 'mapbox-location-indicator-layer';
    } else {
      puckLayerId = 'puck';
    }

    try {
      bool? puckLayerExists =
          await mapboxMap?.style.styleLayerExists(puckLayerId);

However when you use the same code for Android, it fails. The error tells you the puck layer does not exist.

In order to fix this you need to add enabled: true

    mapboxMap?.location.updateSettings(
      LocationComponentSettings(
        enabled: true, // Needed for Android
        pulsingEnabled: false,
        showAccuracyRing: true,
        puckBearing: PuckBearing.COURSE,
        puckBearingEnabled: true,
      ),
    );

I think this behavior should be consistent across iOS and Android. So I guess the bug is that when enabled: true is not provided on iOS it still adds the puck layer.

@evil159
Copy link
Contributor

evil159 commented Jun 17, 2024

Hi @basvdijk, thank you for making the report. May I ask what's the reason you are trying to access the location indicator layer? Just so we don't run into the XY problem.

@basvdijk
Copy link
Author

@evil159 I need to "snap" the puck on a route so it nicely follows the route line. As far as I know there is no listener I can use which is triggered when the puck location changes I do the following:

  • set the location puck with an opacity of 0.01
  • start a timer with an interval of 16ms (equals 60 fps).
  • get the current puck location
  • find the nearest point on my route line
  • draw my own location puck on this snapped position

A 100% nicer solution would be if there is if there is a 'onPuckLocationChangedoronLocationChanged` where I can do this. It would save me a timer.

@evil159
Copy link
Contributor

evil159 commented Jun 27, 2024

Thank you for sharing your use case @basvdijk! We have location API in our road map, can't give exact estimate, but it's close to the top of the list.

@basvdijk
Copy link
Author

@evil159 Great to hear! When implementing could you please make a flag or something so I can subscribe to GPS changes and the actual puck position (because of the smooth movement, don't want to interpolate myself).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants