通过Google Places API获取附近地点的列表(快速3) [英] Get list of nearby places from Google Places API (Swift 3)

查看:110
本文介绍了通过Google Places API获取附近地点的列表(快速3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道已经有类似的威胁,但是,我正在寻找的 exact 主题似乎没有被触及.

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

我是一名编程新手,但是,我实现了运行该应用程序的功能,该应用程序可获取您的当前位置,将坐标转换为地址,并能够将您的位置数据存储在tableView中.

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.

现在,我正在寻找一种方法,该方法如何借助Google Places API获取附近的商店列表并在表格视图中显示.我只能在如何在地图视图上显示POI方面找到很多帮助,但是,我只想在列表中显示这些POI(例如"Walmart,1st Avenue,1234 Waltown").

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?

非常感谢!

德国最好的, 乔纳斯(Jonas)

All the best from Germany, Jonas

推荐答案

轻量级解决方案!

我创建了一个Google包装器,以在此处通过api呼叫Google: Google Api帮助器

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
    }
}

有趣的是,我添加了一个奖励api来获取附近的所有60个地方,因此用户不必担心下一页令牌并调用api直到最终结果到来.这是获取所有结果的示例.

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)

这篇关于通过Google Places API获取附近地点的列表(快速3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆