my VALID and ENABLED Google API Key is generating a REQUEST_DENIED response from the Maps Geocoding API when I request Reverse Geocoding. The same GOOGLE_API_KEY works perfectly on the same project with Maps Static API and Maps SDK for Android API. And YES, I have enabled the Geocoding API for billing.
I don't understand why it does not work, please help.
MY CODE:
static Future<String> getPlaceAddress(double lat, double lng) async {
final url = Uri.parse(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=$GOOGLE_API_KEY');
final response = await http.get(url);
return json.decode(response.body)['results'][0]['formatted_address'];
}
ERROR MESSAGE ON CONSOLE:
Performing hot reload...
Syncing files to device sdk gphone x86...
Reloaded 1 of 960 libraries in 533ms.
D/MediaScannerConnection(10267): Scanned /data/user/0/com.example.dm_places/cache/d3bef27d-313a-4d37-8159-035faf606d438754135540374763487.jpg to null
D/EGL_emulation(10267): eglCreateContext: 0xf4525150: maj 2 min 0 rcv 2
I/flutter (10267): a
I/flutter (10267): File: '/data/user/0/com.example.dm_places/app_flutter/scaled_d3bef27d-313a-4d37-8159-035faf606d438754135540374763487.jpg'
I/flutter (10267): {error_message: You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account, results: [], status: REQUEST_DENIED}
E/flutter (10267): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
E/flutter (10267): #0 List.[] (dart:core-patch/growable_array.dart:260:36)
E/flutter (10267): #1 LocationHelper.getPlaceAddress (package:dm_places/helpers/location_helper.dart:19:49)
E/flutter (10267): <asynchronous suspension>
E/flutter (10267): #2 Places.addPlace (package:dm_places/providers/places.dart:21:21)
E/flutter (10267): <asynchronous suspension>
E/flutter (10267):
The error message says that you are not using an API key in your request. It seems that it is because of the amp;
in the request so the key
parameter in the end is omitted. Remove that amp;
and your request will work.