0

First of all I want to say that I have checked all the related answers to this question and none of them is working for me as I think they are now old and doesn't seem to work with the new apis.

  1. How to use Google Places API in Android?
  2. Can i use google Places API in android?
  3. Google Places API - android

Above are the few links that I have checked.

I am trying to get the nearby restaurants using the places api in which radius will be defined by user using a seekbar. Here is how I am creating my request

private String getUrl(double latitude, double longitude, String nearbyPlace, int radius) {

    StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/search/json?");
    googlePlacesUrl.append("location=" + latitude + "," + longitude);
    googlePlacesUrl.append("&radius=" + radius);
    googlePlacesUrl.append("&type=" + "restaurants");
    googlePlacesUrl.append("&sensor=true");
    googlePlacesUrl.append("&keyword=" + nearbyPlace);
    googlePlacesUrl.append("&key=" + "xxxxxxxxxxxxxx");
    Log.d("getUrl", googlePlacesUrl.toString());
    return (googlePlacesUrl.toString());

}

I pass the above created url to an asynctask to fetch the result from it.

But everytime I am trying to request I get the below error.

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

I have signed up for google cloud platform too in case that is the issue but that doesn't help either.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
  • **I have checked all the related answers...** in such case you must add links of those question so that people here will not misunderstood and mark it duplicate or ignore it. – Vikasdeep Singh Aug 11 '18 at 14:44
  • @VicJordan added links now – Vivek Mishra Aug 11 '18 at 14:48
  • Did you enable Places API Web Service in your project? Double check if API key has any API restriction. Probably Places API web service is not allowed for given API key. – xomena Aug 12 '18 at 10:42
  • Also note that you have to use separate API key for Google Maps Android SDK and for web services. API key for Android SDK has Android app restriction that is not valid for web services. You can check which restriction is supported by each API here: https://developers.google.com/maps/faq#keysystem – xomena Aug 12 '18 at 10:45
  • @xomena Everything I did was correct. Problem was that google places api says it takes 5 minutes after enabling to get activated. But in real it took more time than that. So I was actually checking after almost exact 5 minutes and it was not working. I left it for about 2-3 hours and it started working after that. – Vivek Mishra Aug 13 '18 at 05:22

1 Answers1

1

I solved the problem myself.Everything I did was correct. Problem was that google places api says it takes 5 minutes after enabling to get activated. But in real it took more time than that. So I was actually checking after almost exact 5 minutes and it was not working. I left it for about 2-3 hours and it started working after that.

Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84