TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by Francis Beasley.
OpenCageSDK
works on iOS 9+ and requires ARC to build. It depends on the following Apple frameworks, which should already be included with most Xcode templates:
You will need the latest developer tools in order to build OpenCageSDK
. Old Xcode versions might work, but compatibility will not be explicitly maintained.
You will also need an API key from OpenCage to initialise this SDK. The API key is retrieved from here: https://geocoder.opencagedata.com/
CocoaPods is the recommended way to add OpenCageSDK to your project.
pod 'OpenCageSDK'
pod install
@import OpenCageSDK
Alternatively you can directly add the source files to your project, they are found under OpenCageSDK/Classes.
You can also add OpenCageSDK as a static library to your project or workspace.
OpenCageSDK.xcodeproj
onto your project or workspace (use the "Product Navigator view").OpenCageSDK
. You might also need to add OpenCageSDK
to the Target Dependencies list.#import [yourprojectname]-swift.h
.OpenCageSDK is built on top of NSURLSession with a completionBlock so the network requests happen on a background thread, for setting up the SDK there is a convenience initialiser.
let ocSDK :OCSDK = OCSDK(apiKey: "YOUR-API-KEY")
OCSDK *sdk = [[OCSDK alloc] initWithApiKey:@"YOUR-API-KEY"];
Reverse Geocoding is done through the method below, any errors with the request are on the completionBlock 'error'. The response from the server is parsed into objects for ease of access.
let ocSDK :OCSDK = OCSDK(apiKey: "YOUR-API-KEY")
ocSDK.reverseGeocode(latitude: NSNumber(value: 51.5159), longitude: NSNumber(value: 0.1297), withAnnotations: true) { (response, success, error) in
if success {
//Successful payload response
}
}
OCSDK *sdk = [[OCSDK alloc] initWithApiKey:@"YOUR-API-KEY"];
[sdk reverseGeocodeWithLatitude:@(51.5159) longitude:@(0.1297) withAnnotations:YES completionBlock:^(OCGeoResponse * _Nonnull response, BOOL success, NSError * _Nullable error) {
if (success) {
// Successful payload response
}
}];
Forward Geocoding is done through the method below, any errors with the request are on the completionBlock 'error'. The response from the server is parsed into objects for ease of access.
let ocSDK :OCSDK = OCSDK(apiKey: "YOUR-API-KEY")
ocSDK.forwardGeocode(address: "3 Walls Court, Tewkesbury, England", withAnnotations: true) { (response, success, error) in
if success {
//Successful payload response
}
}
OCSDK *sdk = [[OCSDK alloc] initWithApiKey:@"YOUR-API-KEY"];
[sdk forwardGeocodeWithAddress:@"3 Walls Court, Tewkesbury, England" withAnnotations:YES completionBlock:^(OCGeoResponse * _Nonnull response, BOOL success, NSError * _Nullable error) {
if (success) {
// Successful payload response
}
}];
Documentation is provided in the OCSDK.swift file as well.
This code is distributed under the terms and conditions of the MIT license.