Repository navigation
Google Maps onCameraIdle not working in iOS when in a Stack. #33988
Copy link
Copy link
Closed
Labels
a: platform-viewsEmbedding Android/iOS views in Flutter appsEmbedding Android/iOS views in Flutter appscustomer: googleVarious Google teamsVarious Google teamsp: mapsGoogle Maps pluginGoogle Maps pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specifically
Milestone
Description
Steps to Reproduce
I have a layout where in a Stack I have a GoogleMap, a GestureDetector on top of it that currently absorbs all the taps and doesn't pass it to the GoogleMap. Once tapped, GestureDetector allows the taps to be passed onto GoogleMap.
Problem is, whenever I make this kind of layout, the onCameraIdle callback is not being called in iOS (works in Android). Double tapping the map or tapping on a marker somehow resets the callback, but it doesn't work the first time.
class FancyMapPageState extends State<FancyMapPage> {
...
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
GoogleMap(
...
),
GestureDetector(
behavior: !_animationController.isCompleted
? HitTestBehavior.opaque
: HitTestBehavior.deferToChild,
onTap: () {
_animationController.forward();
},
),
SlideTransition(
position: _cardSlideAnimation,
Container(
child: ...,
),
),
],
);
}
}
Logs
No issues found! (ran in 5.9s)
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F132, locale en-IN)
• Flutter version 1.5.4-hotfix.2 at /Users/gurleensethi/Documents/Flutter/flutter
• Framework revision 7a4c33425d (5 weeks ago), 2019-04-29 11:05:24 -0700
• Engine revision 52c7a1e849
• Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/gurleensethi/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2.1, Build version 10E1001
• ios-deploy 1.9.4
• CocoaPods version 1.5.3
[✓] Android Studio (version 3.4)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 35.3.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[✓] IntelliJ IDEA Community Edition (version 2019.1.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 36.0.4
• Dart plugin version 191.7830
[✓] VS Code (version 1.35.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.1.0
[✓] Connected device (1 available)
• Gurleen’s iPhone • 2e3ceb53501346b6a4d1b2e0ac2abf9850737cc5 • ios • iOS 12.3.1
• No issues found!
@iskakaushik Could you please look into this, thanks in advance :)
Edit by cyanglaz:
internal b/144584399
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: platform-viewsEmbedding Android/iOS views in Flutter appsEmbedding Android/iOS views in Flutter appscustomer: googleVarious Google teamsVarious Google teamsp: mapsGoogle Maps pluginGoogle Maps pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specifically
Activity
leen-nobbas commentedon Jun 6, 2019
A complete sample example:
darwin-morocho commentedon Jun 29, 2019
I have the same problem
ludowkm commentedon Jul 4, 2019
I also met this problem, any suggestion ?
droidpl commentedon Jul 27, 2019
Same problem here. This is critical to do thing on camera movement that require an await, as there is no other callback to do this
ludowkm commentedon Jul 29, 2019
I overcome it by a workaround, on onCameraMove, i make a delay subscription 150 milliseconds then the result will be onCameraIdle, but before subscribe it, do cancelling first because onCameraMove will be call multiple times before. Like the below:
onCameraMove: (newPosition) { _mapIdleSubscription?.cancel(); _mapIdleSubscription = Future.delayed(Duration(milliseconds: 150)) .asStream() .listen((_) => _onCameraIdle()); }papalardo commentedon Aug 21, 2019
I have the same problem, but when I move List on the Map
DennisKragekjaer commentedon Aug 26, 2019
Same issue here. Its becoming worrying how many problems there is with google maps/ platform views.
I have same structure as you, with a button on top of Google maps. When I press the button everything related to map stops working, no onIdle and so on. When I tap a marker or double tap the maps, it is working again, until I press the button.
leen-nobbas commentedon Aug 26, 2019
@justinmc Can we have this on priority?
papalardo commentedon Aug 26, 2019
alright that's palliative
justinmc commentedon Aug 27, 2019
CC @amirh
idompolo commentedon Aug 27, 2019
Update the camera using mapController for button click event.
example)
onTap: () {
setState(() {
_isOpen = false;
});
mapController.animateCamera(...)
},
Camera update, for example, does not change the actual screen if the zoom value is equal to the existing value.
dipendra-sharma commentedon Dec 11, 2019
Any solution for this?
15 remaining items
goderbauer commentedon Feb 19, 2020
Looks like there's no b/ bug attached to this. Removing customer: google and critical labels.
cyanglaz commentedon Feb 19, 2020
@goderbauer I am going to attaching the b/ bug and relabel it.
TimG38 commentedon Mar 18, 2020
If it's any help, here's some additional information on how to reproduce it:
google_maps_flutter: ^0.5.24+1masewo commentedon Apr 13, 2020
@cyanglaz Can you please push your solution to a branch so that we do not have to wait for the engine fix to hit stable?
asksage commentedon Apr 25, 2020
I just wrote a CustomPanGestureDetector that doesn't fully consume events (tested on iOS Simulator). I hope this helps:
https://github.com/asksage/rawFiles/blob/master/custom_pan_detector.dart
Wrap your GoogleMap widget like this:
RawGestureDetector( gestures: <Type, GestureRecognizerFactory>{ CustomPanGestureDetector: GestureRecognizerFactoryWithHandlers<CustomPanGestureDetector>( () => CustomPanGestureDetector( onPanStart: _onDown, onPanEnd: _onUp, ), (CustomPanGestureDetector instance) {}, ), }, child: GoogleMapasksage commentedon Apr 25, 2020
Please, note I am not returning event.position in the callbacks (so add that if you need it) because I just wrote this to test the concept.
MarcinusX commentedon Apr 30, 2020
@asksage solution didn't solve the problem for me.
I've put @TimG38 code to gist: https://gist.github.com/MarcinusX/97230719f58e6835b0761f369d88b608
The bug still occurs on version
0.5.27. Tested on simulator iPhone11baldwizard commentedon May 5, 2020
I stumbled on this issue today. I thought about a simple workaround that might be helpful in some cases (although i am sure it doesn't solve every case ... ). The idea is rather simple - keep track of the last position to which camera got moved :
The good thing is that it will reset reading events by google maps widget back to normal the bad side is that it will create few unwanted events.
baldwizard commentedon May 6, 2020
Btw. you can restrict issuing .moveCamera events to minimum by checking if onCameraMove event ended with onCameraIdle event:
It should issue moveCamera events only when onCameraMove event doesn't get terminated with onCameraIdle event.
Update: it seems that it's just safer to issue .moveCamera events every time button is clicked (restricting them will prevent this workaround from working in some cases)
cyanglaz commentedon May 12, 2020
This issue has been fixed in flutter-team-archive/plugins#2746
Please update the plugin to 0.5.27+3 to apply the fix.
I'm closing the issue.
github-actions commentedon Aug 21, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.