适用于 iOS 的 Google Directions API SDK,完全用 Swift 编写。
PXGoogleDirections
项目添加到您的 Xcode 项目中如果您的应用还需要 Google Maps iOS SDK,您可能会遇到由于 CocoaPod 中的捆绑 Google Maps iOS SDK 而产生的冲突问题。如果遇到这些问题,请尝试以下操作
-framework "GoogleMaps"
添加到 Xcode 项目的“其他链接器标志”中。GoogleMaps.bundle
。如果不包含,您可以通过在 Finder 中浏览以下目录手动将其添加到 Xcode 中:/Pods/PXGoogleDirections/Dependencies/GoogleMaps.framework/Resources/GoogleMaps.bundle
。将其拖入项目的“框架”组中,并取消选中“复制”复选框。使用两行Swift代码快速上手
1) 创建API对象
let directionsAPI = PXGoogleDirections(apiKey: "<insert your Google API key here>",
from: PXLocation.CoordinateLocation(CLLocationCoordinate2DMake(37.331690, -122.030762)),
to: PXLocation.NamedLocation("Googleplex", "Mountain View", "United States"))
2) 运行路线请求
directionsAPI.calculateDirections( (response) -> Void in {
switch response {
case let .Error(_, error):
// Oops, something bad happened, see the error object for more information
break
case let .Success(request, routes):
// Do your work with the routes object array here
break
}
})
有关可用属性和响应数据的更多信息,请参阅下面的“文档”。
此存储库的“样品”子文件夹中提供了一个示例项目,可帮助您开始使用SDK。
PXGoogleDirections SDK采用新BSD许可证授权。(更多信息请见LICENSE文件。)
欢迎您通过Github、Twitter、Stack Overflow或电子邮件与我联系