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

前端 未结 3 1732
闹比i
闹比i 2021-01-05 14:02

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, howev

3条回答
  •  猫巷女王i
    2021-01-05 14:49

    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)
    

提交回复
热议问题