Nico teWinkel
Nico teWinkel

Reputation: 880

Google Places nearbysearch from Android?

I'm having trouble figuring out how to call the Google Places API from Android. Specifically I'm looking at the nearbysearch call right now.

This is the full URL as it is sent: (minus my API key)

https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=49.7088,-124.9712&radius=3000&sensor=true&key=YourAPIKeyHere

I'm getting this error returned:

<error_message>This IP, site or mobile application is not authorized to use this API key.</error_message>

I went through the whole process in the Google Developers Console in terms of getting the API key, adding my app to the allowed list, adding the library (google-play-services_lib) and settings to my project, adding the api key and gms.version entries to the manifest, but it still fails.

To test that setup part, I added a Google Map to the same Activity, and it shows up properly - this indicates that my app is properly in the allowed list, and that my API key is correct (it's a String resource that's used in the Manifest as well as in the URL), or else the map wouldn't show any of the graphics.

The question: How can I make a Google Places nearbysearch call from Android?

Thanks!

Upvotes: 0

Views: 1428

Answers (1)

Scott
Scott

Reputation: 3732

I think you're mixing up some of the tools here. The Google Places API does not require any additional libraries. You do not need to have Google Play Services in your app. It is simply an http call.

Google did just announce that they're adding Place APIs to Play Services, which should eventually replace the HTTP API, but you don't need to use it yet and I haven't even seen the documentation, just the announcement.

First, here's the link to the Places API instructions: https://developers.google.com/places/documentation/#Authentication

Make sure that when you're looking at your credentials, your Android key says, "Any Application Allowed".

Credential Example

Here's a sample implementation in Java using an open source HTTP class called WebRequest:

String TempSQL = "https://maps.googleapis.com/maps/api/place/nearbysearch/xml?" 
                            + GMapI_Key
                            + "&location=" + coordinatesString
                            + "&rankby=distance&types=establishment&name="
                            + placeName;
            new WebRequest().get().to(TempSQL).executeAsync(new WebRequest.Callback() {
                public void onSuccess(int responseCode, String responseText) {
                    //Your code here
                }
                public void onError() {
                    //throw new RuntimeException("NoWebResponse");
                }
            });

Upvotes: 1

Related Questions