Puck layer not added the same way on iOS and Android
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.
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.
@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.
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.
@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).