Swiftpack.co - what3words/w3w-swift-components as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by what3words.
what3words/w3w-swift-components v2.3.0
A swift library to use What3words autosuggest
⭐️ 0
🕓 2 weeks ago
.package(url: "https://github.com/what3words/w3w-swift-components.git", from: "v2.3.0")

CircleCI

what3words w3w-swift-components

Overview

A Swift library for what3words UI components. These depend on the what3words swift wrapper.

For information on using this package with Objective-C read this

If you are upgrading from any version 1.x.x, see the upgrade guide.

Compatibility

These components work with iOS 9.0 or higher.

Installation

Authentication

To use this library you’ll need a what3words API key, which can be signed up for here. If you wish to use the Voice API calls then you must add a Voice API plan to your account.

Swift Package Manager

You can install with Swift Package Manager by adding the URL below to Swift Packages under your project settings:

https://github.com/what3words/w3w-swift-components.git

Import the libraries:

import W3WSwiftApi
import W3WSwiftComponents
import CoreLocation

src="https://raw.github.com/what3words/w3w-swift-components/master/# Note:

If you are using the Voice API on device, you should include Microphone permissions in your Infsrc="https://raw.github.com/what3words/w3w-swift-components/master/st:

Components

AutoSuggest Text Field

Full documentation can be found at Documentation/Autosuggest/autosuggest.md.

An iOS UIKit example project can be found at Examples/TextField/TextField.xcodeproj

W3WAutoSuggestTextField is a UITextField that src="https://raw.github.com/what3words/w3w-swift-components/master/suggest three word addresses as the user types.

This conforms to our W3WAutoSuggestTextFieldProtocol for returning any addresses the user choses, as well as to set options.


AutoSuggest Search Controller

Full documentation can be found at Documentation/Autosuggest/autosuggest.md.

An iOS UIKit example project can be found at Examples/TextField/TextField.xcodeproj

W3WAutoSuggestSearchController is a UISearchController that will suggest three word addresses as the user types. This allows embedding this functionality in things such asUINavigationController and MKMap

This also conforms to our W3WAutoSuggestTextFieldProtocol for returning any addresses the user choses, as well as to set options.

Map Helper

Map Helper allows you to easily integrate what3words map features into an existing map.

W3WMapHelper conforms to W3WMapViewProtocol. A function reference for it can be found at Documentation/Map/map.md

An iOS UIKit example project can be found at Examples/MapHelper/MapHelper.xcodeproj

let api = What3WordsV3(apiKey: "YourApiKey")
let mapHelper = W3WMapHelper(api, map: yourMKMapView)

If your app already has a ViewController that has a map, W3WMapHelper provides convenience functions to add to your MKMapViewDelegate functions for what3words grid and pin annotations to appear on your map. The example linked to above shows where you would place the calls, and how to instantiate the W3WMapHelper.

Map View

W3WMapView conforms to W3WMapViewProtocol . A function reference for it can be found at Documentation/Map/map.md

An iOS UIKit example project can be found at Examples/MapView/MapView.xcodeproj

let api = What3WordsV3(apiKey: "YourApiKey")
let mapview = W3WMapView(api)

We created W3WMapView as a quick and dirty way to quickly get what3words functionality into your app.

Simply replace your MKMapView with W3WMapView, and your app should besrc="https://raw.github.com/what3words/w3w-swift-components/master/the same as before except it will draw what3words grid lines, and have some new functions available, like addMarker(at: "filled.count.soap").

It's derived from MKMapView but Apple does not recommend deriving new objects from MKMapView presumably because it's interface could change in the future, so view this as a quick and dirty way to get the functionality into your app.

The better approach would be to use W3WMapHelper which is designed to fit nicely into your MKMapViewDelegate conforming class, presumably a UIViewController.

Map Component

W3WMapViewController conforms to W3WMapViewProtocol . A function reference for it can be found at Documentation/Map/map.md

The iOS UIKit example project can be found at Examples/MapComponent/MapComponent.xcodeproj

let api = What3WordsV3(apiKey: "YourApiKey")
let vc = W3WMapViewController(api)

This demonstrates W3WMapViewController which is a high level component that has easy to use what3words functionality.

If you already have a map in your application then you will want to use W3WMapHelper instead. Find the example called MapHelper.

If you have no map in your app and want to quickly include one with some default behaviours then this one might be for you.

Settings

Measurements

The measurement system in these components are set to the user's preference or locale automatically, but you can override this to .metric, or .imperial:

W3WSettings.measurement = .metric

Localizations

The W3WAutosuggest components have been translated into about 50 languages, and Localizable.strings files for these are in the Resources of this package. In order for them to work, as with any iOS localisation settings, be sure to add the languages you want to use in your project settings under Info -> Localizations.

GitHub

link
Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics