Google Directions API helper for iOS, written in Swift

Last update: Mar 11, 2022

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

  • Supports all features from the Google Directions API as of August 2018 (see here for a full list: https://developers.google.com/maps/documentation/directions)
  • Supports "open in Google Maps app", both for specific locations and directions request
    • also supports the callback feature to get the user back to your app when he's done in Google Maps
    • in case the Google Maps app is not installed, also supports fallback to the built-in Apple Maps app
  • Available both with modern, Swift-style completion blocks, or Objective-C-style delegation patterns
  • Queries are made over HTTPS
  • JSON is used behind the scenes to help reduce the size of the responses
  • Available through CocoaPods and Carthage

🆕 New in V1.6

  • Compatibility with Google Places IDs (usage: PXLocation.googlePlaceId("gplaceid"), or PXLocation.googlePlaceId(gmsPlace.placeID) if you're already using Google's Places SDK for iOS)
  • Compatibility with Swift 4.2
  • Updated to Google Maps iOS SDK 2.7
  • Availability through Swift Package Manager (cancelled for V1.6)

🆕 New in V1.5.1

  • Updated to Google Maps iOS SDK 2.5
  • The PXGoogleDirections Pod is now released as a static library (requires Cocoapods 1.4.0)
  • Other bug fixes

🆕 New in V1.4

  • Compatibility with Swift 4
  • Availability through Carthage
  • Slight improvements to projects mixing this pod with Google Maps and/or Google Places pods (but mixing Google Maps iOS SDK with other Pods is still terrible...)

🆕 New in V1.3

  • Full Swift 3 support
  • Full Google Maps iOS SDK 2.0+ support
  • Added a trafficModel property on the PXGoogleDirections class to match Google's one in the API (recently added); it works only for driving routes, and when a departure date is specified
  • Fixed a bug where drawing a route would only draw a basic, rough representation of it taken from the route object; now there is an option for drawing a detailed route in the drawOnMap method of the PXGoogleDirectionsRoute class
  • Other small bug fixes

⚠️ Requirements

  • Runs on iOS 9.3 and later.
  • Compatible with Swift 4 / Xcode 9 and later.
    • Please use v1.3 if you are on Swift 3 and/or Xcode 8.
    • Please use v1.2.3 if you need compatibility with a previous version of Swift.
  • The SDK depends on the official Google Maps SDK for iOS (more information here: Google Maps iOS SDK)

💻 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:

  • Clone the repository
  • Add the whole PXGoogleDirections project to your own Xcode project
  • Add a dependency between the two projects and build
  • Do not forget to add the output of the PXGoogleDirections project (PXGoogleDirections.framework) to the "Embedded Binaries" section of your Xcode project's main target

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:

  • GoogleMapsCore
  • GoogleMapsBase
  • GoogleMaps

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:

  • your project's root directory,
  • the PXGoogleDirections submodule's root directory (e.g. Frameworks/External/PXGoogleDirections).
  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:

  • Lots of messages like these at runtime (usually application startup): Class GMSxxx_whatever is implemented in both (name of your app) and (reference to PXGoogleDirections framework). One of the two will be used. Which one is undefined. This is because with Carthage or Cocoapods you usually have two versions of the Google Maps iOS SDK : the one that has been linked with the PXGoogleDirections library, and the one you will be forced to link against in your own application if you wish to use it explicitly. From what I've seen, there is no real impact to these warnings as long as both versions are equivalent. They only pollute your output console at runtime.

  • Messages like these at runtime (usually when showing a Google Maps view): Main Thread Checker: UI API called on a background thread: -[UIApplication setNetworkActivityIndicatorVisible:] This behavior is new to Xcode 9, and it seems like the culprit is the Google Maps iOS SDK itself, not the sample app provided with the library. These messages are not really harmful, but they are not sane either. If you find a solution, please PM me!

  • The framework is not yet ready for Swift Package Manager since it requires static linking to Google Maps iOS SDKs and inclusion of a Google Maps resources bundle; both of those tasks can't be done with Swift Package Manager at this time.

🙏🏻 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:

GitHub

https://github.com/poulpix/PXGoogleDirections
Comments
  • 1. Conflicts with Google Places SDK

    I have pod GooglePlaces in my Podfile specified and I get an error. So, I need to do something else when using GooglePlaces SDK with PXGoogleDirections? PXGoogleDirections is only bundled with GoogleMaps SDK?

    Reviewed by KRUBERLICK at 2017-02-21 14:52
  • 2. draws 2 routes or wrong route calculation

    In a few cases two routes are drawn. Is there any way to just show one of them, even though distance of both may be the same? screen shot 2017-03-11 at 16 58 31

    This is also weird. Any ideas what wrong drawing causes? screen shot 2017-03-11 at 18 43 39

    Reviewed by ghost at 2017-03-11 16:04
  • 3. Google maps and Places from cocoapods

    i still cant add google maps and google places from cocoapods with the solution you provide i got this error " target has frameworks with conflicting names: googlemapsbase.framework, googlemaps.framework, and googlemapscore.framework. " from where you get your version of Google maps and why it is different from pods version ?

    Reviewed by embassem at 2017-01-01 11:41
  • 4. Swift 3

    Hi, I am having trouble build this on swift 3. I am getting the errors:

    screen shot 2016-11-25 at 4 42 59 pm

    as if its not converted yet. Anyone else having trouble with this? Thanks!

    Reviewed by ranleung at 2016-11-26 00:44
  • 5. No such module 'Google Maps'

    I have followed the section "In case of problems" provided in your description though I cannot build my project since a No such module 'Google Maps' error shows up all the time! screen shot 2016-04-12 at 11 39 05 am screen shot 2016-04-12 at 11 39 21 am screen shot 2016-04-12 at 11 39 42 am screen shot 2016-04-12 at 11 41 05 am

    Reviewed by filangelos at 2016-04-12 08:41
  • 6. Overall distance and duration of a route object

    Following Sascha's email, it would be nice to have properties giving the overall distance and duration of a PXGoogleDirectionsRoute object. It might not be possible to return PXGoogleDirectionsDuration and PXGoogleDirectionsDistance objects directly, but at least raw NSTimeInterval and CLLocationDistance objects should be feasible.

    Reviewed by poulpix at 2016-02-17 23:21
  • 7. Compatibility with Google pods - Command failed due to signal: Abort trap: 6

    I've followed the instructions on the readme but i couldn't build the project correctly, below the issue:

    /Users/andrea/Documents/Workspace/myproject-ios/Pods/GoogleMaps/Maps/Frameworks/GoogleMaps.framework/Headers/GMSCoordinateBounds+GoogleMaps.h:24:12: warning: duplicate definition of category 'GoogleMaps' on interface 'GMSCoordinateBounds'
    @interface GMSCoordinateBounds (GoogleMaps)
               ^
    /Users/andrea/Documents/Workspace/myproject-ios/Pods/GoogleMaps/Maps/Frameworks/GoogleMaps.framework/Headers/GMSCoordinateBounds+GoogleMaps.h:24:12: note: previous definition is here
    @interface GMSCoordinateBounds (GoogleMaps)
               ^
    /Users/andrea/Documents/Workspace/myproject-ios/Pods/GoogleMaps/Maps/Frameworks/GoogleMaps.framework/Headers/GMSMapView+Animation.h:22:12: warning: duplicate definition of category 'Animation' on interface 'GMSMapView'
    @interface GMSMapView (Animation)
               ^
    /Users/andrea/Documents/Workspace/myproject-ios/Pods/GoogleMaps/Maps/Frameworks/GoogleMaps.framework/Headers/GMSMapView+Animation.h:22:12: note: previous definition is here
    @interface GMSMapView (Animation)
               ^
    <unknown>:0: error: fatal error encountered while reading from module 'myproject'; please file a bug report with your project and the crash log
    
    *** DESERIALIZATION FAILURE (please include this section in any bug report) ***
    top-level value not found
    Cross-reference to module 'GoogleMaps'
    ... GMSMapView
    
    Reviewed by andr3a88 at 2018-05-25 10:50
  • 8. Library not loaded

    Hi, I installed PXGoogleDirections as a git submodule, it all went fine. I was able to build the two targets, but when I run my project I get:

    dyld: Library not loaded: @rpath/PXGoogleDirections.framework/PXGoogleDirections
      Referenced from: /var/containers/Bundle/Application/7B330ACD-03B9-4B20-A853-59A5ABA3CF67/MaryDrive.app/MaryDrive
      Reason: image not found
    

    Could anyone help me please?

    Reviewed by hpbl at 2018-01-22 21:53
  • 9. http://stackoverflow.com/questions/42725437/the-service-denied-use-of-the-directions-service-by-this-application

    hi please answer this question: http://stackoverflow.com/questions/42725437/the-service-denied-use-of-the-directions-service-by-this-application

    I downloaded your example project but I got this errors: screen shot 2017-03-10 at 22 18 04


    screen shot 2017-03-10 at 22 18 18
    Reviewed by smemamian at 2017-03-10 18:50
  • 10. calculateDirections() return only one PXGoogleDirectionsRoute always.

    directionAPI.from = PXLocation.coordinateLocation(location1) directionAPI.to = PXLocation.coordinateLocation(location2)

    directionAPI.calculateDirections({ response in switch response { case let .error(, error): break case let .success(, routes): print(routes.count) break } })

    Then always return only one value. Please help me.

    Reviewed by hayaoMobile at 2017-03-30 02:15
  • 11. Add New Example

    Add new Example that use Pods to add Goole SDK with 'PXGoogleDirections

    Pods for PodExample

    pod 'GoogleMaps' pod 'GooglePlaces' pod 'PXGoogleDirections'

    we still get Error from cocopods after add -framework to Other Linker Flags "[!] The 'Pods-App' target has frameworks with conflicting names: googlemapsbase.framework, googlemaps.framework, and googlemapscore.framework."

    Reviewed by embassem at 2017-03-22 07:23
  • 12. I can't compile PXGoogleDirections with Xcode 11.5 because it generated with older version of Xcode

    Hello, I can't compile PXGoogleDirections with Xcode 11.5 because it generated with older version of Xcode

    error : Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.2.4 compiler: /Users/dev/Desktop/iviflo/Ios/SmartFlo/PXGoogleDirections.framework/Modules/PXGoogleDirections.swiftmodule/arm64-apple-ios.swiftmodule

    Reviewed by charfddine at 2020-06-25 10:19
  • 13. Import from source

    Hi,

    i want to import the project from source. My project is composed by a Workspace with the app and the pods project

    From the readme:


    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:

    • Clone the repository
    • Add the whole PXGoogleDirections project to your own Xcode project
    • Add a dependency between the two projects and build
    • Do not forget to add the output of the PXGoogleDirections project (PXGoogleDirections.framework) to the "Embedded Binaries" section of your Xcode project's main target

    What means Add the whole PXGoogleDirections project to your own Xcode project and Add a dependency between the two projects and build?

    PXGoogleDirections should be added at workspace level or myproject level?

    Reviewed by andr3a88 at 2018-11-29 09:15
  • 14. Unable to find and load 'GoogleMaps.bundle'

    updated PXGoogleDirections pod to 1.6 ( running Xcode 10 and swift4.2 ) and when accessing a view with map it crashes generating this error

    WARNING: Unable to find and load 'GoogleMaps.bundle' for Google Maps SDK for iOS. This may be a sign that you've forgotten to include a resources bundle in your 'Copy Bundle Resources' build phase. As this bundle contains important resources, you may encounter missing images, translations and other incorrect behavior. Terminating app due to uncaught exception 'GMSServicesException', reason: 'Google Maps SDK for iOS requires GoogleMaps.bundle to be part of your target under 'Copy Bundle Resources'

    Reviewed by mohamedsalahnassar at 2018-09-26 13:20
MSFlightMapView allows you to easily add and animate geodesic flights to Google map

MSFlightMapView Demo Requirements iOS 10.0+ Xcode 9.0+ Installation Just add the MSFlightMapView folder to your project. or use CocoaPods: pod 'MSFlig

Apr 24, 2022
A spatial analysis library written in Swift for native iOS, macOS, tvOS, watchOS, and Linux applications, ported from Turf.js.

Turf for Swift ?? ?? ?? ?? ⌚️ A spatial analysis library written in Swift for native iOS, macOS, tvOS, watchOS, and Linux applications, ported from Tu

Jun 16, 2022
Location, motion, and activity recording framework for iOS

LocoKit A Machine Learning based location recording and activity detection framework for iOS. Location and Motion Recording Combined, simplified Core

Jun 13, 2022
Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL

Mapbox GL Native A C++ library that powers customizable vector maps in native applications on multiple platforms by taking stylesheets that conform to

Jun 23, 2022
JDSwiftMap is an IOS Native MapKit Library. You can easily make a highly customized HeatMap.
JDSwiftMap is an IOS Native MapKit Library.  You can easily make a highly customized HeatMap.

JDSwiftMap is an IOS Native MapKit Library. You can easily make a highly customized HeatMap. Installation Cocoapods pod 'JDSWiftHeatMap' Usage JDSwi

Jun 18, 2022
The Swift Geometry Engine.
The Swift Geometry Engine.

Easily handle a geometric object model (points, linestrings, polygons etc.) and related topological operations (intersections, overlapping etc.). A ty

Jun 24, 2022
A Swift wrapper for forward and reverse geocoding of OpenStreetMap data

Nominatim NominatimKit is a Swift wrapper for forward and reverse geocoding of OpenStreetMap data. Why? Geocoding location data on iOS requires the us

Feb 5, 2022
Aplicativo criado para estudos de desenvolvimento de Mapa e GPS usando Swift
Aplicativo criado para estudos de desenvolvimento de Mapa e GPS usando Swift

Onde_estou_iOS Aplicativo criado para estudos de desenvolvimento de Mapa e GPS usando Swift, onde ele pede autorização para usar GPS e localização do

Nov 14, 2021
A Swift package for parsing Clang module map files

Clangler is a Swift package used to parse Clang module map files into an abstract syntax tree (AST) representation. Once parsed, you can inspect or manipulate the nodes in the file, then generate and save a new file reflecting your changes.

Apr 7, 2022
Use Swift in the macOS command line to build maps.
Use Swift in the macOS command line to build maps.

Use Swift in the macOS command line to build maps. imagefrom A Swift command line utility that gets an image from a URL. Saves the web image as JPEG o

Dec 30, 2021
Google Directions API helper for iOS, written in Swift
Google Directions API helper for iOS, written in Swift

PXGoogleDirections Google Directions API SDK for iOS, entirely written in Swift. ?? Features Supports all features from the Google Directions API as o

Mar 11, 2022
An easy to integrate Model Based Google Maps Helper (SVHTTPClient, AFNetworking) That lets you Geo Code , Reverse Geocode, Get Directions , Places Autocomplete.

GoogleMapsHelper Read Me in Russian : http://gargo.of.by/googlemapshelper/ A GOOGLE MAPS Helper that help you do multiple tasks like HOW TO USE // usi

Feb 21, 2019
Google-Blogger-iOS-App - Using Google Blogger API to build an iOS app like Medium

Google Blogger iOS App Using Google Blogger API to build an iOS app like Medium!

May 16, 2022
OsmAnd (OSM Automated Navigation Directions)
 OsmAnd (OSM Automated Navigation Directions)

OsmAnd (OSM Automated Navigation Directions) This project aims at providing comfortable map viewing and navigation (routing) application for mobile de

Jun 21, 2022
Google Analytics tracker for Apple tvOS provides an easy integration of Google Analytics’ measurement protocol for Apple TV.

Google Analytics tracker for Apple tvOS by Adswerve About Google Analytics tracker for Apple tvOS provides an easy integration of Google Analytics’ me

Dec 10, 2021
An extremely simple JSON helper written in Swift.

Alexander Alexander is an extremely simple JSON helper written in Swift. It brings type safety and Foundation helpers to the cumbersome task of JSON u

Dec 24, 2021
iOS helper library that contains commonly used code in Uptech iOS projects

iOS helper library that contains commonly used code in Uptech iOS projects.

Apr 1, 2022
iONess is HTTP Request Helper for iOS platform used by HCI iOS App

iONess iONess (iOS Network Session) is HTTP Request Helper for the iOS platform used by Home Credit Indonesia iOS App. It uses Ergo as a concurrent he

Mar 28, 2022
Sweet-swift - Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper Functions and Common Utilities

Sweet Swift Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper F

Feb 6, 2022
Helper functions for saving text in Keychain securely for iOS, OS X, tvOS and watchOS.
Helper functions for saving text in Keychain securely for iOS, OS X, tvOS and watchOS.

Helper functions for storing text in Keychain for iOS, macOS, tvOS and WatchOS This is a collection of helper functions for saving text and data in th

Jun 21, 2022