flutter googlemapsapi-通过点击InfowDindow更改路线
我对Flutter是很新的,我正在尝试根据Googlemaps构建一个应用程序。现在,我添加了多个标记,当您第一次弹出信息窗口时点击它们时。然后,点击信息窗口后,我想将路由更改为另一个屏幕,然后包括该地点的描述等。 但是,我现在正在努力敲击Infowdow之后可以更改路线,这意味着当我点击它时什么都不会发生。
是否可以在InfowDindow上使用“ ONTAP”功能?我为任何解决方案感到高兴。
我当前在标记部分的代码:
markers.add(Marker( //add first marker
markerId: MarkerId(showLocation.toString()),
position: showLocation, //position of marker
infoWindow: InfoWindow( //popup info
title: 'Marker Title First ',
snippet: 'My Custom Subtitle',
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
},
),
icon: BitmapDescriptor.defaultMarker, //Icon for Marker
));
我刚刚在此问题上找到了一个据称有效的解决方案( google_maps_flutter,marker ontap(){}不起作用),但是,由于我必须初始化字段' buildContext'。我在之前使用了“迟到”,但它仍然不起作用。
我们发现了这个问题,我给了多个标记以相同的标记。更改后,它可以正常工作。对不起,案件关闭了!
I am pretty new to Flutter and I am trying to build an App based on GoogleMaps. Now I added multiple markers and when you tap them the first time a info window pops up. Then, after tapping the info window, I want to change route to another screen, which then includes the description of the place etc.
However, I am struggling now with making it possible to change route after tapping the infowindow, meaning nothing happens when I tap it.
Is it possible to use the 'OnTap' function on the infowindow? I'm happy for any solutions.
My current code for the marker section:
markers.add(Marker( //add first marker
markerId: MarkerId(showLocation.toString()),
position: showLocation, //position of marker
infoWindow: InfoWindow( //popup info
title: 'Marker Title First ',
snippet: 'My Custom Subtitle',
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
},
),
icon: BitmapDescriptor.defaultMarker, //Icon for Marker
));
I just found a supposedly working solution on this problem (Problem with google_maps_flutter, marker onTap(){} doesn't work), however, I guess due to the implementation of null safety it is not working anymore, since I had to initialize the field 'BuildContext'. I did so using 'late' before it, but it still does not work.
We found the problem, I have given multiple markers the same MarkerId. After I changed it, it worked fine. Sorry guys, case closed!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论