Home

Awesome

PXGoogleDirections

Google Directions API SDK for iOS, entirely written in Swift.

Cocoapods Cocoapods Swift

Cocoapods compatible Cocoapods CocoaPods CocoaPods CocoaPods CocoaPods

Carthage compatible Swift Package Manager incompabible

GitHub stars GitHub forks GitHub watchers Twitter Follow

🗺 Features

🆕 New in V1.6

🆕 New in V1.5.1

🆕 New in V1.4

🆕 New in V1.3

⚠️ Requirements

💻 Installation

From Carthage

To use PXGoogleDirections in your project add the following line to your Cartfile:

github "Poulpix/PXGoogleDirections"

Alternatively, if you wish to target a specific version of the library, simply append it at the end of the line in the Carttfile, e.g.: github "Poulpix/PXGoogleDirections" ~> 1.5.


Then run the following command from the Terminal:

carthage update

Finally, back to Xcode, drag & drop the generated framework in the "Embedded Binaries" section of your target's General tab. The framework should be located in the Carthage/Build/iOS subfolder of your Xcode project.

Dropping a Carthage-generated framework in Xcode


Important: Carthage is only supported starting from version 1.4 of this library. Previous versions of this library will not work.


From Cocoapods

To use PXGoogleDirections in your project add the following Podfile to your project:

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.3'
use_frameworks!

pod 'PXGoogleDirections'

Then run the following command from the Terminal:

pod install

Important: If your project needs both PXGoogleDirections and Google Maps and/or Google Places iOS SDK, you will run into problems. Please see the "Compatibility with Google pods" paragraph below, and do not hesitate to contact me and describe your issue if you require assistance!


From source

Building from raw source code is the preferred method if you wish to avoid known issues with the Google Maps iOS SDK conflicts with the library. However, you'll be lacking the automation and version updates the Cocoapods and Carthage frameworks provide.

To build from source, follow these simple steps:

Adding the PXGoogleDirections framework as an embedded binary in Xcode

⌨️ Usage

Quick-start in two lines of Swift code:

  1. Reference the library like this:
import PXGoogleDirections
  1. Create an API object:
let directionsAPI = PXGoogleDirections(apiKey: "<insert your Google API key here>",
    from: PXLocation.coordinateLocation(CLLocationCoordinate2DMake(37.331690, -122.030762)),
    to: PXLocation.specificLocation("Googleplex", "Mountain View", "United States"))
  1. Run the Directions request:
directionsAPI.calculateDirections({ response 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
 }
})

Important: You normally don't need to call GMSServices.provideAPIKey() yourself: it will be called by PXGoogleDirections when initializing the SDK.


See "Documentation" below for more information on the available properties and response data.

📚 Documentation

The SDK provides an integrated documentation within Xcode, with full autocomplete support.

To help getting you started, a sample project is also available in the "Sample" subfolder of this repository.

It is designed to demo the main features of both the API and the SDK.

Sample app screenshot 1 Sample app screenshot 2

😱 Compatibility with Google pods

Since V1.3, PXGoogleDirections uses Google's latest branch of Google Maps iOS SDK, which has now been split into smaller, more modular frameworks. PXGoogleDirections has a dependency with three of them:

The Google Places iOS SDK is not required.

If your app also requires the Google Maps iOS SDK (for drawing on a map, for example), you will run into troubles because of conflicts with the bundled Google Maps iOS SDK in the pod. This is because of Google's way of releasing its pods as static frameworks, and not dynamic ones.

Here is the only workaround known to date:

  1. Remove PXGoogleDirections from your Podfile and issue a pod update.
  2. Add all the Google dependencies to your Podfile (e.g.: pod GoogleMaps, pod GooglePlaces) and issue a pod update.
  3. Open a Terminal in your folder's root folder, and reference PXGoogleDirections as a git submodule, like this:
git submodule add https://github.com/poulpix/PXGoogleDirections.git Frameworks/External/PXGoogleDirections

This will download all of the PXGoogleDirections project in a subfolder of your own project (Frameworks/External/PXGoogleDirections). Of course you can change this path if you like.


Important: You may also request a specific version of the framework by adding the -b <branch> switch to the git submodule command, like this:

git submodule add -b <branch> https://github.com/poulpix/PXGoogleDirections.git Frameworks/External/PXGoogleDirections

To find out the appropriate branch name, check out all the available branches on Github


  1. Update your Podfile to give instructions on how to build both your project and the PXGoogleDirections submodule:

    source 'https://github.com/CocoaPods/Specs.git'
    
    workspace 'test.xcworkspace' # Your project's workspace
    project 'test.xcodeproj' # Your project's Xcode project
    project 'Frameworks/External/PXGoogleDirections/PXGoogleDirections.xcodeproj' # Update folder structure if needed
    
    target 'test' do
       project 'test.xcodeproj'
       platform :ios, '10.0' # Update for your needs
    
       use_frameworks!
    
       # Update these lines depending on which Google pods you need
       pod 'GoogleMaps'
       pod 'GooglePlaces'
       # Other pods...
    end
    
    # This tells Cocoapods how to build the subproject
    target 'PXGoogleDirections' do
       project 'Frameworks/External/PXGoogleDirections/PXGoogleDirections.xcodeproj'
       platform :ios, '9.3'
    
       pod 'GoogleMaps'
    end
    
  2. Now you need to do a pod install in two locations:

  1. Open Xcode with your project.xcworkspace and build the PXGoogleDirections target, then your app's target. Everything should build properly.

💣 Known issues

Depending on your setup, you might see one or several of these known issues:

🙏🏻 Credit

📜 License

The PXGoogleDirections SDK is licensed under the New BSD license. (see LICENSE for more information.)

📮 Contact

Don't hesitate to drop me a line on Github, Twitter, Stack Overflow, or by email: