使用谷歌放置Web API来搜索业务,使用结果进行电话呼叫

时间:2022-08-22 10:23:15

I'm working on a project, and I'm completely stuck.

我正在做一个项目,完全被困住了。

I get the user's location using CLLocation and am able to get the place name using CLGeocoder, and using this I've constructed a URL to search the Google Places Web API.

我使用CLLocation获得用户的位置,并能够使用CLGeocoder获得位置名称,并使用它构造了一个URL来搜索谷歌位置Web API。

My question is, how can I actually complete the search and return the top place result's phone number? Any help would be much appreciated!

我的问题是,我如何完成搜索并返回顶部结果的电话号码?如有任何帮助,我们将不胜感激!

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

This is the URL I've come up in case that helps

这是我找到的URL,如果有用的话

1 个解决方案

#1


1  

The first thing you need to do is an HTTP GET on the URL to get the API results. Consult the following SO question for various ways to do that:

您需要做的第一件事是在URL上设置一个HTTP GET来获取API结果。咨询以下问题,以各种方式做到这一点:

How to make an HTTP request in Swift?

如何在Swift中发出HTTP请求?

The data returned will be a JSON document in the format described in the Google Places API Docs. Look for the formatted_phone_number and/or international_phone_number fields. See Working with JSON in Swift for how to parse the JSON string.

返回的数据将是一个JSON文档,格式在谷歌Places API文档中描述。查找formatted_phone_number和/或international_phone_number字段。有关如何解析JSON字符串,请参阅在Swift中使用JSON。

#1


1  

The first thing you need to do is an HTTP GET on the URL to get the API results. Consult the following SO question for various ways to do that:

您需要做的第一件事是在URL上设置一个HTTP GET来获取API结果。咨询以下问题,以各种方式做到这一点:

How to make an HTTP request in Swift?

如何在Swift中发出HTTP请求?

The data returned will be a JSON document in the format described in the Google Places API Docs. Look for the formatted_phone_number and/or international_phone_number fields. See Working with JSON in Swift for how to parse the JSON string.

返回的数据将是一个JSON文档,格式在谷歌Places API文档中描述。查找formatted_phone_number和/或international_phone_number字段。有关如何解析JSON字符串,请参阅在Swift中使用JSON。