使用 Google Places Web API 搜索商家并使用结果拨打 phone 电话

Using Google Places Web API to search for business and using results to make a phone call

我正在做一个项目,但我完全卡住了。

我使用 CLLocation 获取用户的位置,并且能够使用 CLGeocoder 获取地名,并使用它构建了一个 URL 来搜索 Google Places Web API.

我的问题是,我怎样才能真正完成搜索和 return 首位结果的 phone 数?任何帮助将不胜感激!

let url: URL = URL(fileURLWithPath: "https://maps.googleapis.com/maps/api/place/textsearch/json?query=taxi+" + placeMark.locality!+"&key=" + self.GAPIKEY)

这是我想出的 URL 以防万一

您需要做的第一件事是在 URL 上执行 HTTP GET 以获得 API 结果。请参阅以下 SO 问题以了解各种方法:

返回的数据将是 JSON 文档,其格式在 Google Places API Docs. Look for the formatted_phone_number and/or international_phone_number fields. See Working with JSON in Swift 中描述如何解析 JSON 字符串。