Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected Response Code 400 from Google Maps in Flutter

I am working on a Flutter project and have to integrate Google Maps in my project. To do the same, I created a new project on Gogle console, added Maps SDK for android and other APIs I will need and took the key and copy pasted in my AndroidManisfest.xml file.

<meta-data 
    android:name="com.google.android.geo.API_KEY"
    android:value="my_key_here"    
></meta-data>

Now when I go to my Map screen, it just shows me the blank page with small boxes and Google's icon on bottom left corner and zoom in and zoom out icon on bottom right corner. In console it gives error of

Unexpected response code 400 for https://clients4.google.com/glm/mmap/api

Here is the code of my map.dart screen

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
import 'package:permission_handler/permission_handler.dart';

class ViewMapsScreen extends StatefulWidget {
  @override
  _ViewMapsScreenState createState() => _ViewMapsScreenState();
}

class _ViewMapsScreenState extends State<ViewMapsScreen> {

  Completer<GoogleMapController> _controller = Completer();

  static const LatLng _center = const LatLng(45.521563, -122.677433);

  void _onMapCreated(GoogleMapController controller) {
    _controller.complete(controller);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        child: GoogleMap(
          onMapCreated: _onMapCreated,
          initialCameraPosition: CameraPosition(
            target: _center,
            zoom: 11.0
          )
        ),
      ),
    );
  }
}

Please guys help me out, I am stuck at a rather simple thing to implement.

like image 940
neerav94 Avatar asked Nov 15 '22 13:11

neerav94


1 Answers

To all having this question,

Go to https://console.cloud.google.com/apis/credentials

Add Package name & SHA1 Fingerprint

enter image description here

like image 110
flakerimi Avatar answered Dec 23 '22 05:12

flakerimi