Home » Android » Google Places API Key for Android App

Google Places API Key for Android App

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have created an API Key (for Android apps) for my Android Application. It was required by google maps API. But now the same key won’t work for Google Places API.

I also tried hitting the browser with the following URL:

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=my_key

I get:

{
   "error_message" : "This IP, site or mobile application is not authorized to use this API key.",
   "html_attributions" : [],
   "status" : "REQUEST_DENIED"
}

When I googled for an answer, I found this:

https://developers.google.com/places/training/autocomplete-android

What type of API key?

You’ll need your own browser or server API key for the Google Places API before you can begin using the Place Autcomplete service. Note that an Android API key will not work for the Place Autocomplete service.

This got me confused as I do not have any URL for a web app, nor any server IP. Therefore I am confused on how to get either a Browser key or a Server key

Could anyone please help me in figuring out what sort of key is needed here? Also if I have to create a Browser key or a Server key, how can I do so?

How to&Answers:

see this doc to know how to obtain google places API key

Check out this tutorial for integrating Google places

Answer:

For working with places api generate browser key because for that android key does not work.
Had same issue but this solved the problem

Answer:

You need to enable the following places api

-Google Places API Web Service

And you are required to use server key for fetching the data of places.

To get a server key follow the below steps: APIs & Auth -> Credentials -> create new key -> Server key

Browser key will not work.

I had the same issue and I resolved it by doing the same.

Here you can have a look to build your Url

 StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
            googlePlacesUrl.append("location=" + latitude + "," + longitude);
            googlePlacesUrl.append("&radius=" + PROXIMITY_RADIUS);
            googlePlacesUrl.append("&types=" + type);
            googlePlacesUrl.append("&sensor=true");
            googlePlacesUrl.append("&key=" + SERVER_KEY);

Answer:

If you want to integrate Google Place Api in android project and you need a key, then just click the link below it will automatically create a key for
you and just copy that key in your project

https://developers.google.com/places/android-api/start