CCXGoogleNearbyPlaces
为什么使用 CCXGoogleNearbyPlaces?
- 我制作了这个 CocoaPod 是为了使用 Google Maps 并通过提供一种搜索附近地点的方式来实现,而无需使用他们提供的通用搜索控制器。这给你提供了制作自定义搜索界面的灵活性。
- CCXGoogleNearbyPlaces 继承了 API 的所有选项。它提供了找到地点的图片 URL 以及分页结果,可以按照一组类型/类别或自定义类别进行搜索,并按文本凭据进行搜索。
- CCXGoogleNearbyPlaces 不会使用任何第三方网络工具来完成 API 调用。
示例
要运行示例项目,首先克隆仓库,然后从 Example 目录中运行 pod install
从那里,您可以在 AppDelegate 中设置断点,我们将在那里调用 Nearby Places API 并查看响应,以判断这个 CocoaPod 是否适用于您。
安装
CCXGoogleNearbyPlaces 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中
pod 'CCXGoogleNearbyPlaces'
集成
你需要一个API密钥
模块下载并成功构建完成后,请进入您的AppDelegate文件中导入CCXGoogle NearlyPlaces模块。
接着,请确保您有一个API密钥来使用cocoapod。以下是一些获取API密钥的指导:
配置您的API密钥
从上述链接获取有效API密钥后,您应将api key配置如下
CCXGoogleSDK.places.apiKey = "Your API Key"
使用细节
您可以通过几种方式使用CCXGoogleNearbyPlaces pod来获取结果。您可以使用带有距离和位置的文本参数,API返回20个结果。在响应对象中,我们将指示您是否可以加载更多对象。您可以通过在下一个请求中只传递下一个页面令牌来加载下一页。
使用示例
通过半径、位置坐标和文本参数获取所有附近的地点
let coord = CLLocationCoordinate2D()
// Radius is in meters.
CCXGoogleSDK.places.get(withText: "restaurants", withRadius: 300.4, coordinate: coord) { response in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
self.queueForNextLoad = true
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
仅通过半径和位置坐标获取所有附近的地点
let coord = CLLocationCoordinate2D()
// Radius is in meters.
CCXGoogleSDK.places.get(withRadius: 300.4, coordinate: coord) { response in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
self.queueForNextLoad = true
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
通过下一个页面令牌获取下一页的地点
CCXGoogleSDK.places.get(pageToken: "nextPageToken") { (response) in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
self.queueForNextLoad = true
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
获取指定类型或类别的附近地点
CCXGoogleSDK.places.get(withRadius: 200.4, coordinate: coord, category: .hairCare) { (response) in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
更多
Google 文档链接
作者
ryancoyne, [email protected]
许可协议
CCXGoogleNearbyPlaces 在MIT许可下可用。更多信息请参阅LICENSE文件。