skip to Main Content

Hello Stack Overflow Community,

I’m developing a Flutter app with a Google Maps integration. My map is not displaying, even though the API hits are showing up in the Google Cloud Platform console, indicating that the requests are successful.

Here’s a rundown of what I’ve done so far:

  • Verified that my API key is correctly placed in the AndroidManifest.xml.
  • Set the necessary permissions for location and internet in AndroidManifest.xml.
  • Tested the app on a emulator.
  • Ensured the API key is activated for the correct project on the Google Cloud Platform without any restrictions.
  • Updated to the latest versions of Flutter and the google_maps_flutter plugin.

Below is the core code snippet from my implementation in dart:

class CirclesPage extends StatefulWidget {
  const CirclesPage({Key? key}) : super(key: key);

  @override
  _CirclesPageState createState() => _CirclesPageState();
}

class _CirclesPageState extends State<CirclesPage> {
  GoogleMapController? _controller;
  LatLng currentLocation = LatLng(46.8182, 8.2275); // Default to Switzerland

  @override
  void initState() {
    super.initState();
    _determinePosition().then((_) => _goToCurrentLocation());
  }

  void _onMapCreated(GoogleMapController controller) {
    _controller = controller;
    _goToCurrentLocation();
  }

  Future<void> _goToCurrentLocation() async {
    if (_controller == null) return;
    _controller!.animateCamera(CameraUpdate.newLatLngZoom(currentLocation, 15.0));
  }

  Future<void> _determinePosition() async {
    // Location service check and permission handling logic
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Maps Sample')),
      body: GoogleMap(
        onMapCreated: _onMapCreated,
        myLocationEnabled: true,
        initialCameraPosition: CameraPosition(
          target: currentLocation,
          zoom: 15.0,
        ),
      ),
    );
  }
}

Logs confirm that initState, onMapCreated, and build functions are called, but the screen where the map is supposed to appear remains blank.

I would greatly appreciate any suggestions or insights on what I might be missing or what steps I should take next to resolve this issue.

Thank you in advance!

UPDATE 1: I’m on it now. It is very likely that I made a mistake with the SHA-1 key. I will take care of the issue and delete the question if necessary.

UPDATE 2: Unfortunately, the renewal of the SHA-1 key has not shown any positive development.
The only time the request and the display of the map works is when I execute the following commands in terminal:

flutter clean

flutter pub get

and then call the page

2

Answers


  1. Chosen as BEST ANSWER

    Thank you very much for your feedback. I have already found and checked this reference. I am already fulfilling your suggestion. However, your feedback is already helping to narrow down the error further.

    My extract from AndroidManifest.xml


  2. I tried running your code and the map displayed correctly for me. This suggests the issue might be with your specific setup.
    enter image description here

    What helped me resolve a similar "map not showing" in the past is placing my API key within the application tag in the android/app/src/main/AndroidManifest.xml file.

    Like so:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search