This package provides components to help your user find an old fashioned street address from a three word address by connecting with 3rd party address validation services. It supports <!--- Loqate, ---> Data8, Swift Complete, and any other services currently in the w3w-swift-address-validators package which is a dependancy of this package.
There is an iOS UIKit component and a watchOS SwiftUI component.
When installing the Swift Package you can choose either or both of:
W3WSwiftComponentsAddressValidator
W3WSwiftUIComponentsAddressValidator
Notice the first one is prefixed with W3WSwift
and the second W3WSwiftUI
. The first one uses UIKit and works on iOS, iPadOS, and macCatalyst. The second is designed for watchOS and is written in SwiftUI.
Create an account with either <!--- Loqate, ---> Data8, or Swift Complete and get an API key from them.
When instantiating the component for UIKit or SwiftUI the second parameter takes the key sets the service. Use the appropriate parameter and label:
data8ApiKey: String
swiftCompleteApiKey: String
If you use this component you will also need a what3words API key. This is to enable the voice input and what3words autosuggest. If you only want to use an address validator service you can use our Address Validator wrapper (w3w-swift-address-validators) instead and build out your own UI interface. The wrapper takes a three word address as input and doesn't need voice or autosuggest support. This package has a dependancy on that wrapper.
The UIKit version is W3WSuAddressValidator
. It is derived from a UIViewController
. Simply instantiate it and present it on your view stack, preferably in a popup modal view.
var api = What3WordsV3(apiKey: "YourWhat3wordsApiKey")
let validator = W3WAddressValidatorViewController(w3w: api, swiftCompleteApiKey: "yourSwiftCompleteApiKey")
// set the focus to a nearby location
let options = W3WOptions().focus(gpsLocation)
validator.set(options: options)
// present the view controller
show(validator, sender: self)
// closure for when the address has been selected by the user
validator.onAddressSelected = { address in
print(address.description)
}
An example can be found in /Examples/WatchOS/WatchOSAddressValidator.xcodeproj
The watchOS SwiftUI version takes the various service API keys and also a completion block for the results:
// body of the view
var body: some View {
W3WSuAddressValidator(w3wApiKey: "YourWhat3wordsApiKey, swiftCompleteApiKey: "yourSwiftCompleteApiKey", coordinates: location) { address in
print(address.description)
}
}
link |
Stars: 1 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics