Using Google Places API in Android

2019-01-08 09:58发布

问题:

I am trying to develop an app which can display the schools and airports in the locality. I found that using Google Places API is the way to go.

I have seen the documentation here... Can anyone explain how to use the API?

回答1:

New tutorial available

It appears that the original tutorial by Brian is now 404, so here is a link to the Google one in case people see this answer first.

https://developers.google.com/places/android-api/current-place-tutorial

When this article was first written this tutorial didn't exist.


Original:

You could try this tutorial (now 404): http://blog.brianbuikema.com/2010/08/android-development-part-1-using-googles-places-api-to-develop-compelling-location-based-mobile-applications/



回答2:

You can find a tutorial on the Places API in a J2SE environment, using the Google APIs Client Library for Java on my blog. It also includes a sample application in Github that might get you started.

If should be fairly easy to port to Android, as the Google APIs Client Library for Java is Android compatible.



回答3:

You will have to get familiar with HttpClient, HttpRequest, and HttpResponse if you're not already.

Very simply:
Step 1) build your uri with your api key and search terms as per google's syntax
Step 2) perform a post using that uri
Step 3) decode the response from the post

Happy coding :)



回答4:

The point is that you have to build the URL, create the HttpRequest and get the data in XML or JSON format. After that, you may parse this data to get the information you want. Most of people do it in each use, but I think the best option is to have an API for that purpose.

I have developed an API which builds the URL, connects and gets the data in a list of objects that represent places in a well structured OOP design. And everything happen in background in an AsyncTask, which returns the information through an interface/listener. https://github.com/perezdidac/google-places-api.



回答5:

see this link for Showing nearby places using Google Places API

try this