CCXGoogleNearbyPlaces 1.0.2

CCXGoogleNearbyPlaces 1.0.2

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新版本2017年11月
SwiftSwift 版本4.0
SPM支持 SPM

Ryan Coyne维护。



  • Ryan Coyne

CCXGoogleNearbyPlaces

CI Status
Version
License
Platform

为什么要使用 CCXGoogleNearbyPlaces?

  • 我创建这个 Cocoapod 是为了使用 Google Maps 并提供一种在不需要他们提供的通用搜索控制器的情况下搜索附近地点的方法。这为您提供了创建自定义搜索 UI 的灵活性。
  • CCXGoogleNearbyPlaces 通过 API 提供了所有选项。它不仅提供了找到的地点的图片 URL,还提供了分页结果,可以根据设置的类型/类别或自定义类别进行搜索,并通过文本来进行搜索。
  • CCXGoogleNearbyPlaces 不会使用其他第三方网络工具来完成 API 调用。

示例

要运行示例项目,请首先克隆仓库,并在 Example 目录下运行 pod install

从那里,你可以在 AppDelegate 中设置一个断点,我们调用 Nearby Places API 并给出响应,看看这个 Cocoapod 是否对你有用。

安装

CCXGoogleNearbyPlaces 通过 CocoaPods 提供。要安装
它,只需将以下行添加到你的 Podfile 中

pod 'CCXGoogleNearbyPlaces'

集成

你需要一个 API密钥

一旦你下载并成功构建了该模块,请转到你的 AppDelegate 文件并导入 CCXGoogleNearlyPlaces 模块。

然后你需要确保你有一个 API 密钥来使用这个 Cocoapod。请参考以下内容以获得你的 API 密钥

配置你的 API 密钥

一旦你从以上链接中获得有效的 API 密钥,你将设置你的 api 密钥如下

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文件。