google_maps_flutter_web and google_maps_flutter works only locally but not when hosting to firebase

huangapple go评论83阅读模式
英文:

google_maps_flutter_web and google_maps_flutter works only locally but not when hosting to firebase

问题

I'm trying to make google maps works in flutter web app, I used google_maps_flutter and google_maps_flutter_web, It only works in locally when I run it but when I build and upload the project to firebase hosting it is not working.

in web/index.html

  1. <script src="https://maps.googleapis.com/maps/api/js?key=<mykey>&callback=Function.prototype"></script>

My simple flutter code:

  1. import 'package:flutter/material.dart';
  2. import 'package:google_maps_flutter/google_maps_flutter.dart';
  3. import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
  4. void main() => runApp(GoogleMaps());
  5. class GoogleMaps extends StatefulWidget {
  6. const GoogleMaps({Key? key}) : super(key: key);
  7. @override
  8. State<GoogleMaps> createState() => _GoogleMapsState();
  9. }
  10. class _GoogleMapsState extends State<GoogleMaps> {
  11. LatLng ll = LatLng(37.77483, -122.41942);
  12. @override
  13. Widget build(BuildContext context) {
  14. return MaterialApp(
  15. title: 'Google Maps Demo',
  16. home: Scaffold(
  17. appBar: AppBar(
  18. title: Text('Google Maps Demo'),
  19. ),
  20. body: GoogleMap(
  21. initialCameraPosition: CameraPosition(
  22. target: ll,
  23. zoom: 12,
  24. ),
  25. markers: {
  26. Marker(
  27. markerId: MarkerId('marker_1'),
  28. position: ll,
  29. infoWindow: InfoWindow(
  30. title: 'San Francisco',
  31. ),
  32. ),
  33. },
  34. ),
  35. ),
  36. );
  37. }
  38. }

Does there anything special about firebase or the web for Android and IOS ?

I tried many things and I did not see anyone reported this issue in here or in github.

英文:

I'm trying to make google maps works in flutter web app, I used google_maps_flutter and google_maps_flutter_web, It only works in locally when I run it but when I build and upload the project to firebase hosting it is not working.

in web/index.html

  1. &lt;script src=&quot;https://maps.googleapis.com/maps/api/js?key=&lt;mykey&gt;&amp;callback=Function.prototype&quot;&gt;&lt;/script&gt;

My simple flutter code:

  1. import &#39;package:flutter/material.dart&#39;;
  2. import &#39;package:google_maps_flutter/google_maps_flutter.dart&#39;;
  3. import &#39;package:google_maps_flutter_web/google_maps_flutter_web.dart&#39;;
  4. void main() =&gt; runApp(GoogleMaps());
  5. class GoogleMaps extends StatefulWidget {
  6. const GoogleMaps({Key? key}) : super(key: key);
  7. @override
  8. State&lt;GoogleMaps&gt; createState() =&gt; _GoogleMapsState();
  9. }
  10. class _GoogleMapsState extends State&lt;GoogleMaps&gt; {
  11. LatLng ll = LatLng(37.77483, -122.41942);
  12. @override
  13. Widget build(BuildContext context) {
  14. return MaterialApp(
  15. title: &#39;Google Maps Demo&#39;,
  16. home: Scaffold(
  17. appBar: AppBar(
  18. title: Text(&#39;Google Maps Demo&#39;),
  19. ),
  20. body: GoogleMap(
  21. initialCameraPosition: CameraPosition(
  22. target: ll,
  23. zoom: 12,
  24. ),
  25. markers: {
  26. Marker(
  27. markerId: MarkerId(&#39;marker_1&#39;),
  28. position: ll,
  29. infoWindow: InfoWindow(
  30. title: &#39;San Francisco&#39;,
  31. ),
  32. ),
  33. },
  34. ),
  35. ),
  36. );
  37. }

Does there anything special about firebase or the web for Android and IOS ?

I tried many things and I did not see anyone reported this issue in here or in github.

答案1

得分: 1

减小 google_maps_flutter 包的版本解决了我的问题。

原来是:

  1. google_maps_flutter: ^2.4.0

工作的版本是:

  1. google_maps_flutter: ^2.3.0
英文:

Decreasing the package version of google_maps_flutter solved my problem.

It was:

  1. google_maps_flutter: ^2.4.0

Working one:

  1. google_maps_flutter: ^2.3.0

huangapple
  • 本文由 发表于 2023年4月7日 05:04:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定