Navigation SDK provides a comprehensive toolkit for integrating basic & advanced navigation capabilities into your iOS applications. Whether you're developing a mobile navigation app, a fleet management solution, or a location-based service, our SDK offers the tools you need to deliver seamless and reliable navigation experiences to your users. With the Navigation SDK, you can access a wide range of features, including real-time turn-by-turn navigation, route planning, traffic-aware routing, and waypoint addition. Our SDK is designed to be easy to integrate, allowing you to focus on building compelling navigation experiences without the complexity of managing underlying navigation logic.
Specifications
Before proceeding, ensure that you meet the following prerequisites:
Minimum iOS version: iOS 13.0
Xcode Version: 12 or later
Sample App
We wrote a sample app for the Navigation SDK. Please refer to the sample app for reference.Please refer to theGithub Sample Appfor reference.
Setup Map
You have to download OlaNavigation SDK and import all the xcframeworks in your iOS project. Make sure youembed all the frameworks in General > Frameworks, Libraries and Embedded Content. Next, You need to add Location Permission Authorization in your Info.plist file,
<key>NSLocationWhenInUseUsageDescription</key>
<string>App wants to access your location</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>App wants to access your location</string>
Now, you are good to initialize the OlaMapService,
import OlaMapNavigation
// Default Initialization
let olaMapService = OlaMapService(
auth: .apiKey(key: "API-KEY-FROM-PLATFORM-DASHBOARD"),
tileURL: "TILE-URL",
projectId: "PROJECT-ID-FROM-PLATFORM-DASHBOARD"
)
// Or, Initialize Service as per your need
let olaMapService = OlaMapService(
auth: .apiKey(key: "API-KEY-FROM-PLATFORM-DASHBOARD"),
tileURL: "TILE-URL",
projectId: "PROJECT-ID-FROM-PLATFORM-DASHBOARD",
userId: nil
)
)
Parameter name
Description
apikey
API Key from Platform Dashboard
tileURL
Refer Tiles API in API Reference
projectId
Refer Dashboard for Project Identifier
userId
Custom UserID which is identified by Organization
Load the map using the service instance. Ideally this method should be called in viewdidLoad() method of viewcontroller
To draw an annotation, we need to call setAnnotationMarker with coordinate and Annotation View. Make sure, you have unique Identifier for every nnotation you have on map.
You can remove a marker from the map by calling this method removeAnnotation.
self.olaMap.removeAnnotation(by: "annotation-id")
Polygons
Polygons are designed to define solid regions within a closed loop which can be used to mark a particular zone. They consist of a series of coordinates in an ordered sequence.
You can draw Polygons by calling this method drawPolygon(), here is the example below:
To listen to events, you must implement the OlaMapServiceDelegate protocol. Typically, you implement this protocol on the view controller that displays the map. Below is an example:
override func viewDidLoad() {
super.viewDidLoad()
olaMapservice.loadMap(self.view)
olaMapservice.delegate = self
}
// MARK: OlaMapServiceDelegate
public func didTapOnMap(_ coordinate: OlaCoordinate){
let tapCoordinate = coordinate.getCLCoordinate2D()
print("You tapped at (tapCoordinate.latitude), (tapCoordinate.longitude)")
}
public func didLongTapOnMap(_ coordinate: OlaCoordinate) {
let tapCoordinate = coordinate.getCLCoordinate2D()
print("You long pressed at (tapCoordinate.latitude), (tapCoordinate.longitude)")
}
Map Region changed Events
Using the OlaMapServiceDelegate, you can listen when map region changes. Gesture param with it signifies the reason for change
func mapViewDidChange(gesture: OlaMapGesture) {
// To get the center coordinates of the map this is the optional coordinate
let coordinate = olaMapService.centerCoordinateOfMap
}
func mapViewDidBecomeIdle() {
// To get the center coordinates of the map this is the optional coordinate
let coordinate = olaMapService.centerCoordinateOfMap
}
Navigation
Enhance your mobile app with seamless, turn-by-turn navigation. Harness the capabilities of Ola Maps to deliver real-time navigation with intuitive voice guidance. You can instantiate navigation service as follows
Once Route data is fetched from above section, we can call navigate()api on navigation service to display route and start navigation using following code snippet
self.navigationService.navigate(
jsonData: jsonData,
origin: <Origin_Coordinate>,
destination: <Destination_Coordinate>,
mode: .driving
) { state in
switch state {
case .success(vc: let navigationVC):
// Embed navigationVC in your viewController
case .failed(let error):
print("Error : (error.message)")
}
}
End Navigation
Once navigation has been started it can be terminated any time using following api
self.navigationService.endNavigation()
Navigation callbacks
You can listen to navigation events using the OlaMapNavigationServiceDelegate protocol. Below is an example:
func didNavigationCompleted() {
print("✅ Navigation Completed")
}
func didReroute(_ lastLocation: CLLocation) {
// Call direction API to get new route
}
func regionIsChanging(_ gesture: OlaMapGesture) {
print("ℹ️ Region is changing")
}
Instructions
Text Instructions
Once Navigation starts, user will get callbacks depending on journey progress he is making
func didUpdateVisualInstruction(_ instruction: OlaVisualInstruction) {
// Update label with instruction to indicate next turn to your user
print("*************** == (instruction.tertiaryInstruction)")
}
Audio Instructions
We can enable audio guide for user during journey using following api. Also Voice guidance can be programatically toggled using toggleVoiceNavigation() api
To get callback of when instructions has been played, implement following method from OlaMapNavigationServiceDelegate
func didUpdateAudioInstruction(_ instruction: OlaAudioInstruction) {
// Audio instruction has been played
print("*************** == (instruction.primaryInstruction)")
}
Dependencies
OlaMapNavigationSDK is dependent on following Dependencies