Z4F1
Z4F1

Reputation: 678

How can I search for restaurants using filters with google maps android api?

I'm trying to make an app that finds the users location and then searches for for example nearby restaurants. I have a method to find the users location the only thing that is left is to find the restaurants nearby the user. How can I do this? Plz Help!

Upvotes: 3

Views: 5987

Answers (2)

insomniac
insomniac

Reputation: 11756

I don't know about any native android soultions but you can make a Get request to this Google Places API webservice

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=8.5586,76.8814&radius=500&types=food&sensor=false&key=[Your_KEY]

And parse the Json to get the restaurants nearby

location - Latitude,Longitude of the place

radius - Required radius to search your request

key - Your API Key

types - Types of places to search

Things to do to parse the results

  1. Get an Api key and create a sample request in the browser, You will get a big json result something like this

  2. Goto websites like this which can generate POJO classes for your Json the best configuration is given below: enter image description here

  3. Download files and extract it and add them to your source code,You will get some errors at first because you may not have the annotation libraries in your build.gradle

  4. Add these lines in your app's build.gradle:

    dependencies{ compile 'com.google.code.gson:gson:2.3.1' compile 'javax.annotation:javax.annotation-api:1.2-b01' }

  5. Sync gradle files,And In the code where you get the json String ,deserialize it with Gson like:

YourGooglePlacesClass object=new Gson().fromJson(jsonString,YourGooglePlacesClass.class)

Upvotes: 4

adjuremods
adjuremods

Reputation: 2998

You can check out the PlacePicker API that's native uses the Google Places API for Android. For samples, Google provided it in their googlesamples github repo, you can check those out!

Upvotes: 3

Related Questions