GoogleMapsDirections 1.1.4

GoogleMapsDirections 1.1.4

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布上次发布2018年10月
SPM支持SPM

张红毫维护。



 
依赖项
Alamofire~> 4
ObjectMapper~> 3
 

  • 作者
  • 张红毫

Swift Google Maps API

CI Status

在Swift中使用Google Maps Web Service APIs

GooglePlaces已更名为GooglePlacesAPI,因为官方的GooglePlaces库即将到来。

特性

要求

  • iOS 9.0+ / Mac OS X 10.11+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+
  • Swift 3.0+

安装

CocoaPods

  • Google Maps Directions API

    use_frameworks!
    pod 'GoogleMapsDirections', '~> 1.1'
  • Google 地点 API

    use_frameworks!
    pod 'GooglePlacesAPI', '~> 1.1'

用法

  • Google Maps Directions API
    import GoogleMapsDirections
    
    GoogleMapsDirections.provide(apiKey: "A VALID GOOGLE MAPS KEY")
    
    let origin = GoogleMapsDirections.Place.stringDescription(address: "Davis Center, Waterloo, Canada")
    let destination = GoogleMapsDirections.Place.stringDescription(address: "Conestoga Mall, Waterloo, Canada")
    
    // You can also use coordinates or placeID for a place
    // let origin = Place.Coordinate(coordinate: LocationCoordinate2D(latitude: 43.4697354, longitude: -80.5397377))
    // let origin = Place.PlaceID(id: "ChIJb9sw59k0K4gRZZlYrnOomfc")
    
    GoogleMapsDirections.direction(fromOrigin: origin, toDestination: destination) { (response, error) -> Void in
      // Check Status Code
      guard response?.status == GoogleMapsDirections.StatusCode.ok else {
        // Status Code is Not OK
        debugPrint(response?.errorMessage)
        return
      }
      
      // Use .result or .geocodedWaypoints to access response details
      // response will have same structure as what Google Maps Directions API returns
      debugPrint("it has \(response?.routes.count ?? 0) routes")
    }
  • Google 地点 API
    • 地点补全
      import GooglePlacesAPI
      
      GooglePlacesAPI.provide(apiKey: "A VALID GOOGLE MAPS KEY")
      
      GooglePlacesAPI.placeAutocomplete(forInput: "Pub") { (response, error) -> Void in
        // Check Status Code
        guard response?.status == GooglePlaces.StatusCode.ok else {
          // Status Code is Not OK
          debugPrint(response?.errorMessage)
          return
        }
        
        // Use .predictions to access response details
        debugPrint("first matched result: \(response?.predictions.first?.description)")
      }
      
    • 地点详情
      import GooglePlacesAPI
      
      GooglePlacesAPI.provide(apiKey: "A VALID GOOGLE MAPS KEY")
      
      GooglePlacesAPI.placeDetails(forPlaceID: "ChIJb9sw59k0K4gRZZlYrnOomfc") { (response, error) -> Void in
        // Check Status Code
        guard response?.status == GooglePlaces.StatusCode.ok else {
          // Status Code is Not OK
          debugPrint(response?.errorMessage)
          return
        }
        
        // Use .result to access response details
        debugPrint("the formated address is: \(response?.result?.formattedAddress)")
      }

许可证

MIT 许可协议(MIT)

版权所有(c)2015 张宏昊

以下情况下,任何人可以免费获得本软件及相关文档的副本(以下简称“软件”),并在不受限制的情况下处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可及/或出售软件副本,并允许软件权利人进行如下操作,前提如下

上述版权声明和许可声明必须包含在软件的所有副本或实质性部分中。

软件按“原样”提供,不提供任何形式的明示或暗示保证,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他法律行为,还是来自软件或其使用或其他事宜。