0

I added Google Maps API to Flutter app and it keeps returning a blank screen with the error Unexpected response code 400 for https://clients4.google.com/glm/mmap/api

I added the API to every possible location and I've made dozens of new API KEYS and projects, disabled and enabled API's, ran Flutter Clean 15 times, read the documentation TWICE, read a couple of Stack Overflow questions and did everything every answer and comment said but NOTHING, Can anyone please help. IOS:

import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    GMSServices.provideAPIKey("KEY HERE")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Android:

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

//
//
minSdkVersion 20

Maps.dart:

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

  static final kInitialPosition = LatLng(-33.8567844, 151.213108);

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

class _MappState extends State<Mapp> {
  PickResult? selectedPlace;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Google Map Place Picker"),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              ElevatedButton(
                child: Text("Load Google Map"),
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) {
                        return PlacePicker(
                          apiKey: "KEY HERE",
                          // APIKeys.apiKey,
                          initialPosition: Mapp.kInitialPosition,
                          useCurrentLocation: true,
                          selectInitialPosition: true,

                          //usePlaceDetailSearch: true,
                          onPlacePicked: (result) {
                            selectedPlace = result;
                            Navigator.of(context).pop();
                            setState(() {});
                          },
                        );
                      },
                    ),
                  );
                },
              ),
              selectedPlace == null
                  ? Container()
                  : Text(selectedPlace?.formattedAddress ?? ""),
            ],
          ),
        ));
  }
}
Tyrone
  • 17
  • 7
  • What tutorial or documentations have you followed? – Yrll Mar 29 '23 at 07:43
  • I'm guessing that the 400 response code is most likely caused by a billing issue. So do make sure that all is good on that part since 400 response code is a client-side error. – Yrll Mar 29 '23 at 07:51
  • 1
    Thank you @Yrll I have found the solution, it was very simple – Tyrone Mar 29 '23 at 15:28

1 Answers1

0

I have found the extremely simple solution to this error, the problem was that the <meta-data code was not in the right position (I followed a video and in the video he puts it after the <activity, but this is incorrect) it should be right after the <application...> code

Please feel free to read the docs for more information: https://developers.google.com/maps/documentation

Tyrone
  • 17
  • 7
  • 1
    Experienced this yesterday when I was working with some flutter project and tried to put the meta-data for the android module. One thing that helped me really is check the console and I believe it mentions there that there's some issue with finding the API key. That helped me deduce that there was something wrong with how I was implementing the metadata. – Yrll Mar 30 '23 at 01:45
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 31 '23 at 20:26