Google Directions API helper for iOS written in Swift

This app will help you to easily download Google Maps Directions API onto your iOS device.

The “google maps directions api ios swift” is a Google Directions API helper for iOS written in Swift. It can be used to easily get directions from one point to another.

The Google Directions API SDK for iOS is developed completely in Swift.

Characteristics

  • As of August 2018, it supports all elements of the Google Directions API (for a complete list, visit https://developers.google.com/maps/documentation/directions).
  • Both for particular locations and directions requests, “open in Google Maps app” is supported.
    • also supports the callback function, which allows the user to return to your app after he’s finished using Google Maps.
    • If you don’t have Google Maps installed, you may use the built-in Apple Maps program instead.
  • Both current Swift-style completion blocks and Objective-C-style delegation patterns are available.
  • HTTPS is used for all queries.
  • Behind the scenes, JSON is employed to assist minimize the size of the answers.
  • CocoaPods and Carthage both have it.

In V1.6, there are several new features.

  • If you’re already using Google’s Places SDK for iOS, use PXLocation.googlePlaceId(“gplaceid”) or PXLocation.googlePlaceId(gmsPlace.placeID).
  • Swift 4.2 compatibility.
  • Google Maps iOS SDK 2.7 has been updated.
  • Swift Package Manager’s availability (cancelled for V1.6)

V1.5.1 includes a number of new features.

  • Google Maps iOS SDK 2.5 has been updated.
  • The static library for the PXGoogleDirections Pod is now available (requires Cocoapods 1.4.0)
  • Various bug fixes

V1.4 introduces a number of new features.

  • Swift 4 compatibility is a must-have feature.
  • Carthage is a good option.
  • Projects that combine this pod with Google Maps and/or Google Places pods have seen minor improvements (but mixing Google Maps iOS SDK with other Pods is still terrible…)

In V1.3, there are several new features.

  • Swift 3 is fully supported.
  • Support for Google Maps SDK 2.0+ on iOS
  • To mirror Google’s (just introduced) trafficModel field in the API, I added one to the PXGoogleDirections class; it only works for driving routes and when a departure date is supplied.
  • There is now an option for drawing a detailed route in the drawOnMap method of the PXGoogleDirectionsRoute class; previously, 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 minor issues have been addressed.

Requirements are a set of rules that must be followed.

  • It requires iOS 9.3 or later to run.
  • Swift 4 / Xcode 9 and later are supported.
    • If you’re using Swift 3 and/or Xcode 8, please use v1.3.
    • If you require compatibility with an older version of Swift, use v1.2.3 instead.
  • The SDK is based on the Google Maps SDK for iOS (more information here: Google Maps iOS SDK)

Arrangements

From the city of Carthage

Add the following line to your Cartfile to utilize PXGoogleDirections in your project:

“Poulpix/PXGoogleDirections” on github


If you want to target a certain version of the library, just add it to the end of the line in the Carttfile, for example: github “Poulpix/PXGoogleDirections” > 1.5.


Then, from the Terminal, perform the following command:

Update on Carthage

Finally, return to Xcode and drag the produced framework into the “Embedded Binaries” area of the General tab of your project. The framework should be under your Xcode project’s Carthage/Build/iOS subdirectory.

Dropping a Carthage-generated framework in Xcode


Important: Carthage is only supported in this library from version 1.4. This library’s previous versions will not function.


Cocoapods are used in this recipe.

Add the following Podfile to your project if you want to utilize PXGoogleDirections:

platform:ios, ‘9.3’ use frameworks! pod ‘PXGoogleDirections’ source ‘https://github.com/CocoaPods/Specs.git’

Then, from the Terminal, perform the following command:

install pod


Important: You will have issues if your project requires both PXGoogleDirections and Google Maps and/or Google Places iOS SDK. Please review the “Compatibility with Google pods” section below, and if you have any questions, please email me and detail your problem!


according to the source

If you want to avoid known difficulties with the Google Maps iOS SDK and the library, building from source code is the best option. However, you’ll be missing out on the Cocoapods and Carthage frameworks’ automation and version upgrades.

Follow these basic steps to build from source:

  • Duplicate the repository.
  • In your own Xcode project, include the whole PXGoogleDirections project.
  • Create a dependency between the two projects and then build them together.
  • Don’t forget to include the PXGoogleDirections project’s output (PXGoogleDirections.framework) to your Xcode project’s primary target’s “Embedded Binaries” section.

⌨️ Usage

In only two lines of Swift code, you can get started:

  1. As an example, here’s how to cite the library:

PXGoogleDirections should be imported.

  1. Create an API object by following these steps:

PXGoogleDirections(apiKey: “”, from: PXLocation.coordinateLocation(CLLocationCoordinate2DMake(37.331690, -122.030762), to: PXLocation.specificLocation(“Googleplex”, “Mountain View”, “United States”))

  1. Execute the Directions command:

break case let.success(request, routes): / Do your work with the routes object array here break case let.error(_, error): / Oops, something awful occurred, read the error object for more details break case let.success(request, routes): / Do your work with the routes object array here break )


GMSServices should not be called in most cases. PXGoogleDirections will call provideAPIKey() when the SDK is initialized, so do it yourself.


For further information on the accessible attributes and response data, see “Documentation” below.

Documentation is required.

Within Xcode, the SDK includes integrated documentation with full autocomplete capability.

A example project is also provided in the “Sample” subdirectory of this repository to assist you in getting started.

Its purpose is to demonstrate the API’s and SDK’s primary functionalities.

Sample app screenshot 1 Sample app screenshot 2

Compatibility with Google pods is a plus.

PXGoogleDirections has been using Google’s newest branch of the Google Maps iOS SDK since version 1.3, which has been separated into smaller, more modular frameworks. Three of these are dependent on PXGoogleDirections:

  • GoogleMapsCore
  • GoogleMapsBase
  • GoogleMaps

It is not necessary to use the Google Places iOS SDK.

If your app also needs the Google Maps iOS SDK (for example, to draw on a map), you’ll run into issues due to conflicts with the pod’s associated Google Maps iOS SDK. This is due to Google’s decision to provide their pods as static frameworks rather than dynamic ones.

The only known workaround is as follows:

  1. PXGoogleDirections should be removed from your Podfile and a pod update should be performed.
  2. Add all Google dependencies to your Podfile (for example, pod GoogleMaps, pod GooglePlaces) and update the pod.
  3. Open a Terminal in the root folder of your folder and add PXGoogleDirections as a git submodule, as seen below:

Frameworks/External/PXGoogleDirections.git git submodule add https://github.com/poulpix/PXGoogleDirections.git

This will download the whole PXGoogleDirections project and place it in a subdirectory of your own (Frameworks/External/PXGoogleDirections). You may, of course, deviate from this route if you like.


Important: You may also ask for a particular version of the framework by using the -b parameter with the git submodule command, as seen below:

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

Check through all of Github’s available branches to determine the correct branch name.


  1. Update your Podfile to include instructions for both your project and the PXGoogleDirections submodule’s construction:

    workspace ‘test.xcworkspace’ source ‘https://github.com/CocoaPods/Specs.git’ ‘test.xcodeproj’ is the workspace project for your project. # ‘Frameworks/External/PXGoogleDirections/PXGoogleDirections.xcodeproj’ is the Xcode project for your project. # If necessary, update the folder structure. target ‘test’ do project ‘test.xcodeproj’ platform:ios, ‘10.0’ # Use use frameworks to update for your requirements! # Change these lines to match the Google pods you need. ‘GoogleMaps’ and ‘GooglePlaces’ pods # Other pods… come to an end # This instructs Cocoapods on how to create the PXGoogleDirections subproject. do project ‘Frameworks/External/PXGoogleDirections/PXGoogleDirections.xcodeproj’ platform:ios, ‘9.3’ pod ‘GoogleMaps’ end

  2. You must now install pods in two locations:

  • the root directory of your project,
  • Frameworks/External/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PXGoogleDirections/PX
  1. Open your project in Xcode. Build the PXGoogleDirections target first, then your app’s target in xcworkspace. Everything should be in good working order.

Issues that have been identified

Depending on your configuration, you may encounter one or more of the following issues:

  • At runtime (typically during program launch), you’ll see a lot of notifications like this: Both (name of your app) and (name of your app) use the GMSxxx whatever class (reference to PXGoogleDirections framework). One of the two options will be chosen. It’s unclear which one it is. Because you normally have two versions of the Google Maps iOS SDK with Carthage or Cocoapods: one that has been linked with the PXGoogleDirections library, and one that you will be compelled to link against in your own application if you want to utilize it directly. According to what I’ve observed, these warnings have no significant consequence as long as both versions are identical. At runtime, they merely contaminate your output console.

  • Messages like this appear during runtime (typically when a Google Maps view is displayed): Checker for the Main Thread: On a background thread, the following UI API is called: – setNetworkActivityIndicatorVisible: UIApplication setNetworkActivityIndicatorVisible: UIApplication setNetworkActivityIndicatorV This behavior is new to Xcode 9, and it seems that the Google Maps iOS SDK, not the demo app included with the library, is to blame. These messages aren’t necessarily destructive, but they’re also not rational. Please send me a private message if you discover a solution!

  • The framework isn’t ready for Swift Package Manager yet since it needs static linking to Google Maps iOS SDKs and the inclusion of a Google Maps resources bundle, which Swift Package Manager can’t perform right now.

Credit is due to

Permission

The New BSD license applies to the PXGoogleDirections SDK. (For further details, see LICENSE.)

GitHub

https://github.com/poulpix/PXGoogleDirections

The “google maps-ios github” is a project that provides a Google Directions API helper for iOS written in Swift. The project has been updated to use the latest version of Google Maps, and it’s open source on GitHub.

Related Tags

  • draw polyline on google map ios swift 4
  • google maps ios sdk
  • google maps-ios swift github
  • ios heatmap swift
  • google maps ios sdk release notes