The Baato Swift library makes it easy to integrate the Baato API into existing iOS projects.
This library is available as a CocoaPod. To integrate BaatoSwift to your project, add the following to your Podfile:
source 'https://github.com/baato/BaatoPodSpec.git'
target '${YourApp}' do
use_frameworks!
# Pods for ${YourApp}
pod 'BaatoSwift', '~> ${LatestVersion}'
end
Helper methods in BaatoSwift make it easy to perform API requests to Baato.
After initializing Baato with your access token, the getSearch
method can be used to make requests to the Search API.
// Initialize Baato with your token
let baatoClient = BaatoSwift.API.init(token: "YOUR_BAATO_ACCESS_TOKEN")
// searchQuery is a required parameter
baatoClient.searchQuery = "SearchQuery"
// optional parameters
// number of results to return
baatoClient.searchLimit = 10
// latitude and longitude coordinates, for providing additional geographical context to the search.
baatoClient.searchLat= 27.7172
baatoClient.searchLon= 85.3240
// The type or category of results that the request should return. For example: hospital, cafe etc.
baatoClient.searchType= "hospital"
// radius, in kilometers from the specified lat/lon pair within which to look for results. Only integer values supported.
baatoClient.searchRadius= 50
// Perform the search
baatoClient.getSearch { (result) in
switch result {
case .success(let data):
// response is a [SearchResult]?
print(data?.first?.address, data?.first?.address)
guard let data = data else {
return
}
case .failure(let error):
print(error)
}
}
After initializing Baato with your access token, the getReverse
method can be used to make requests to the Reverse Search API.
// Initialize Baato with your token
let baatoClient = BaatoSwift.API.init(token: "YOUR_BAATO_ACCESS_TOKEN")
// reverseLat and reverseLon are required parameters
baatoClient.reverseLat = latitude
baatoClient.reverseLon = longitude
// Perform the reversh search request
baatoClient.getReverse { (result) in
switch result{
case .success(let data):
// response is a Place object
print(data?.address, data?.name)
case .failure(let error):
print(error)
}
}
After initializing Baato with your access token, the getPlaces
method can be used to make requests to the Places API.
// Initialize Baato with your token
let baatoClient = BaatoSwift.API.init(token: "YOUR_BAATO_ACCESS_TOKEN")
// placeId is a required parameter
baatoClient.placeId = placeId
// Perform the place lookup
baatoClient.getPlaces { (result) in
switch result{
case .success(let data):
// response is a Place object
print(data?.address, data?.name)
case .failure(let error):
print(error)
}
}
After initializing Baato with your access token, the getDirections
method can be used to make requests to the Directions API.
// Initialize Baato with your token
let baatoClient = BaatoSwift.API.init(token: "YOUR_BAATO_ACCESS_TOKEN")
// startLat, startLon, destLat, destLon, navMode are all required parameters
baatoClient.startLat = 27.73405
baatoClient.startLon = 85.33685
baatoClient.destLat = 27.7177
baatoClient.destLon = 85.3278
// Mode is the vehicle profilespecified is an enum with the following values: bike, car and foot
baatoClient.navMode = BaatoSwift.NavigationMode.bike
// Specify if you need alternative routes (only spports two points)
baatoClient.navAlternatives = false
// for instructions optional
baatoClient.navInstructions = true
// Perform the directions request
baatoClient.getDirections {(result) in
switch result{
case .success(let data):
// response is a [NavResponse]?
print(data?.first?.distanceInMeters, data?.first?.timeInMs)
case .failure(let error):
print(error)
}
}
After initializing Baato with your access token, the getMapboxDirections
method can be used to make requests to the Directions API for consuming mapbox direction API.
// Initialize Baato with your token
let baatoClient = BaatoSwift.API.init(token: "YOUR_BAATO_ACCESS_TOKEN")
// startLat, startLon, destLat, destLon, navMode are all required parameters
baatoClient.startLat = 27.73405
baatoClient.startLon = 85.33685
baatoClient.destLat = 27.7177
baatoClient.destLon = 85.3278
// Mode is the vehicle profilespecified is an enum with the following values: bike, car and foot
baatoClient.navMode = BaatoSwift.NavigationMode.bike
// Alternative routes are not supported for mapbox direction (also, only spports two points), optional parameter
baatoClient.navAlternatives = false
// instructions must be set true for mapbox navigation, required parameter
baatoClient.navInstructions = true
// Perform the directions request
baatoClient.getMapboxDirections{(result) in
switch result {
case .success (let data):
guard let data = data else {
return
}
//data is mapbox consumable route response object see baato navigation example for more
case .failure (let error) :
print(error.localizedDescription)
}
}