Google Places API Autocomplete search ACCESS DENIED ERROR: FLUTTER (Issue Not Resolved)

Viewed 33

I am trying to use the Autocomplete search (places suggestions) feature of Google Maps Platform using the Places API.
The API KEY I am using is restricted to a single user (i.e., me) on the Maps Platform.
Approach-1:

 Future<void> onChanged(String value) async {
    print('onChanged() called!');
    if (_sessionToken == null) {
      setState(() {
        _sessionToken = uuid.v4();
      });
    }
    if (isFocused) await getSuggestion(value);
  }

  Future<void> getSuggestion(String input) async {
    print('getSuggestion() called $input');
    String type = '(regions)';
    String components = 'country';
    //print('Inside getSuggestion lat=${provider.latitude}');
    String request =
        '$baseURL?input=$input&key=$API_KEY&sessiontoken=$_sessionToken&location=${appState.startLatLng.latitude},${appState.startLatLng.longitude}&radius=50000&components=country:in';
    print('suggestion request url: $request');
    var response = await http.get(Uri.parse(request));
    print('Response is ${response.body}');
    if (response.statusCode == 200) {
      setState(() {
        predictions = jsonDecode(response.body)['predictions'];
      });
    } else {
      throw Exception('Failed to load predictions');
    }
  }

Problem-
But, when I use it on my Android Phone I get the following error response:

{
"error_message": "This IP, site or mobile application is not authorized to use this API key. Request received from IP address <MY IP HERE>, with empty referer",
"predictions": [],
"status": "REQUEST_DENIED"
}

Approach-2 using https://pub.dev/packages/google_place
Place Autocomplete

var googlePlace = GooglePlace("Your-Key");
var result = await googlePlace.autocomplete.get("1600 Amphitheatre");

Problem- Empty Search suggestion list and request denied status

Search suggestion result: [] REQUEST_DENIED

Please help me understand what the problem is and how to rectify. One of the associated problem is- Not able to fetch polyline polypoints because of restricted Google Maps API Key: Flutter

0 Answers
Related