Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of nearby places from Google Places API (Swift 3)

I am aware that there are similar threats already, however, the exact topic I am looking for seems to not have been touched.

I am a programming newby, however, I achieved to get an app running, which fetches your current location, transforms the coordinates to an address and is able to store your location data in a tableView.

Now I am looking for a way on how to fetch a list of nearby stores with the help of the Google Places API and display them in a table view. I could only find plenty of help on how to display POIs on a map view, however, I would only like to display those in a list (e.g. "Walmart, 1st Avenue, 1234 Waltown).

Is some friendly stranger able to help me?

Thanks a lot in advance!

All the best from Germany, Jonas

like image 387
j___.___j Avatar asked Jun 02 '17 16:06

j___.___j


3 Answers

Here is an example url, where it returns a list of starbucks near your location.

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=(yourlatitude),(yourlongitude)&radius=5000&keyword=starbucks&key=(yourkey)

You can get the key from google console

like image 161
phamot Avatar answered Nov 09 '22 06:11

phamot


Lightweight Solution!

I created a google wrapper to call google near by api here : Google Api Helper

var input = GInput()
input.keyword = "Restaurants"
input.radius = 20000
var location = GLocation()
location.latitude = 26.273178
location.longitude = 73.009545
input.destinationCoordinate = location
GoogleApi.shared.callApi(.nearBy, input: input) { (response) in
    if let data = response.data as? [GApiResponse.NearBy], response.isValidFor(.nearBy){
        // all nearby places
    }
}

Interesting part is I added a bonus api to get all the 60 nearby places so the user don't have to worry about the next page token and call the api till the final result come. Here is an example to get all the result.

var input = GInput()
input.keyword = "Restaurants"
input.radius = 20000
var location = GLocation()
location.latitude = 26.273178
location.longitude = 73.009545
input.destinationCoordinate = location
NearbyExtension.shared.completion = { response in
    if let data = response.data as? [GApiResponse.NearBy], response.isValidFor(.nearBy){
        // all nearby places
    }
}
NearbyExtension.shared.getAllNearBy(input: input)
like image 22
tryKuldeepTanwar Avatar answered Nov 09 '22 07:11

tryKuldeepTanwar


Check this out -->> https://www.raywenderlich.com/109888/google-maps-ios-sdk-tutorial

"Finding Something to Eat" section have what you needs.

like image 45
Jitendra Tanwar Avatar answered Nov 09 '22 06:11

Jitendra Tanwar