Google Directions API helper for iOS, written in Swift

Overview

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:

Comments
  • Conflicts with Google Places SDK

    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?

    help wanted 
    opened by KRUBERLICK 11
  • draws 2 routes or wrong route calculation

    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

    question 
    opened by ghost 5
  • Google maps and Places from cocoapods

    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 ?

    duplicate 
    opened by embassem 4
  • Swift 3

    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!

    not a bug 
    opened by ranleung 4
  • No such module 'Google Maps'

    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

    duplicate 
    opened by filangelos 4
  • Overall distance and duration of a route object

    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.

    enhancement 
    opened by poulpix 4
  • Compatibility with Google pods - Command failed due to signal: Abort trap: 6

    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
    
    help wanted 
    opened by andr3a88 3
  • Library not loaded

    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?

    help wanted 
    opened by hpbl 3
  • http://stackoverflow.com/questions/42725437/the-service-denied-use-of-the-directions-service-by-this-application

    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 question 
    opened by smemamian 3
  • calculateDirections() return only one PXGoogleDirectionsRoute always.

    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.

    not a bug 
    opened by hayaoMobile 2
  • Add New Example

    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."

    enhancement 
    opened by embassem 2
  • I can't compile PXGoogleDirections with Xcode 11.5 because it generated with older version of Xcode

    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

    opened by charfddine 1
  • Import from source

    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?

    investigating 
    opened by andr3a88 0
  • Unable to find and load 'GoogleMaps.bundle'

    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'

    investigating 
    opened by mohamedsalahnassar 0
Releases(1.5.1)
Owner
Romain L
Romain L
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 580 Nov 25, 2022
Backport of iOS 15 formatting api

This is a back-port of the .formatted API in Foundation that was introduced at WWDC '21 for iOS 15, macOS 12.0, tvOS 15.0, and watchOS 8.0.

Simon Salomons 9 Jul 22, 2022
Unofficial iOS/macOS SDK for the Notion API.

NotionClient: a Notion SDK for iOS & macOS Unofficial Notion API SDK for iOS & macOS. This is an alpha version and still work in progress. TODO Featur

David De Bels 15 Aug 4, 2022
Swift implementation of Github REST API v3

GitHubAPI Swift implementation of GitHub REST api v3. Library support Swift 4.2. Work is in progress. Currently supported: Issues API. Activity API(Fe

Serhii Londar 77 Jan 7, 2023
Swift Reddit API Wrapper

reddift reddift is Swift Reddit API Wrapper framework, and includes a browser is developed using the framework. Supports OAuth2(is not supported on tv

sonson 236 Dec 28, 2022
Instagram Private API Swift

SwiftyInsta Please notice SwiftyInsta may not be actively maintained at the moment of you reading this note. Refer to #244 for more info. Instagram of

Mahdi Makhdumi 218 Jan 5, 2023
A Swift client for the OpenAI API.

OpenAI A Swift client for the OpenAI API. Requirements Swift 5.3+ An OpenAI API Key Example Usage Completions import OpenAI

Mattt 161 Dec 26, 2022
Swift Bot with Vapor for Telegram Bot Api

Telegram Vapor Bot Please support Swift Telegram Vapor Bot Lib development by giving a ⭐️ Telegram Bot based on Swift Vapor. Swift Server Side Communi

OleG. 104 Jan 6, 2023
Swift library for the Twitter API v1 and v2

Swift library for the Twitter API v1 and v2

mironal 96 Dec 30, 2022
Swifter - A Twitter framework for iOS & OS X written in Swift

Getting Started Installation If you're using Xcode 6 and above, Swifter can be installed by simply dragging the Swifter Xcode project into your own pr

Matt Donnelly 2.4k Dec 26, 2022
Telegram Bot Framework written in Swift 5.1 with SwiftNIO network framework

Telegrammer is open-source framework for Telegram Bots developers. It was built on top of Apple/SwiftNIO

Pataridze Givi 279 Jan 4, 2023
The swiftest way to build iOS apps that connect to Salesforce

Build iOS apps fast on the Salesforce Platform with Swiftly Salesforce: Written entirely in Swift. Uses Swift's Combine framework to simplify complex,

Michael Epstein 131 Nov 23, 2022
CovidCertificate SDK for iOS

This is the Swiss implementation of the Electronic Health Certificates (EHN) Specification [1] used to verify the validity of Digital Covid Certificates. It is partly based on the reference implementation of EHN's ValidationCore

Swiss Admin 19 Apr 5, 2022
App iOS correspondiente al proyecto twitimer.com de la comunidad MoureDev

⏳ Twitimer iOS Twitimer es una App gratuita para iOS y Android que se ha desarrollado para ayudar a usuarios de Twitch, pero sobre todo pensando en ge

Brais Moure 220 Jan 1, 2023
Desk360 Mobile Chat SDK for iOS

Desk360 Chat iOS SDK Desk360 Chat SDK provides simplicity and usability in one place. With this feature, you can provide live support to your customer

null 5 Sep 21, 2022
WANNA SDK enhances your iOS app with virtual try-on capabilities for shoes and watches

WANNA SDK enhances your iOS app with virtual try-on capabilities for shoes and watches. With this feature, your users will be able to see in real time how the selected product looks on them, just by pointing their smartphone camera at their feet or wrist.

Wannaby Inc. 18 Dec 2, 2022
👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me

RandomUserSwift is an easy to use Swift framework that provides the ability to generate random users and their accompanying data for your Swift applic

Wilson Ding 95 Sep 9, 2022
Swift client for Kubernetes

Table of contents Overview Compatibility Matrix Examples Usage Creating a client Configuring a client Client authentication Client DSL Advanced usage

Swiftkube 94 Dec 14, 2022
SDK for creating Telegram Bots in Swift.

Chat • Changelog • Prerequisites • Getting started • Creating a new bot • Generating Xcode project • API overview • Debugging notes • Examples • Docum

Rapier 349 Dec 20, 2022