Ahoy Maps iOS SDK

The AhoyMaps iOS SDK is built to provide seamless integration of Navigation along with Map functionalities into your app

Features

  • Display a Map with zoom and pan functionality

  • Add marker to the map

  • Remove marker

  • Add a polyline

  • Remove a polyline

  • Add a polygon

  • Remove a polygon

  • Set Zoom level of Map

  • Show traffic flow

  • Show location on Map

  • Load custom themes(Day/Night) etc

  • Gestures(Tap,Long Press & Pan)

  • Navigate from source to destination

  • Restricting the route

  • Preview Map Routes

Installation

Signup for Ahoy Movement Studio and obtain a Subscription Key, you can do so by signing up here

The AhoyMaps SDK for iOS can be downloaded through Cocoapods

  • Install cocoapods on your mac(if you dont have it installed already) by running the following command on the terminal
sudo gem install cocoapods
  • Once the cocoapods on installed navigate to the project directory and create a pod by running the following command in the terminal
pod init
  • Open the file in text editor and add the spec source at the top and the pod name
source 'https://github.com/CocoaPods/Specs'
target 'TestApp' do
use_frameworks!
    #  Pods  for  App
    pod 'AhoyMaps'
end
  • Now open the terminal and run the following command in the terminal
pod install

Usage

  • Open AppDelegate file of your project and add the following
import AhoyMaps
  • Add the SDK initialisation function in the didFinishLaunchingWithOptions function of the AppDelegate, the SDK can be initialised through this function
AhoySDKManager.shared()
.ahoySDKKey("YOUR_AMS_SUBSCRIPTION_KEY")
.headerBackgroundColor(.blue)
.footerBackgroundColor(.white)
.footerAccentColor(.black) //foreground color
.headerAccentColor(.white)
.setAhoyMapKitDelegate(self)
.build()
  • Conform to the AhoySDKManagerDelegate in App delegate by doing so
extension AppDelegate : AhoySDKManagerDelegate {
    func didFailtoInitialiseAhoyMapKitSDK(error: Error) {
        print("AHOY MAPKIT SDK initialisation failed \(error)")
    }
    func didInitialiseAhoyMapKitSDK() {
        print("AHOY MAPKIT SDK initialisation successfull")
    }
}
  • Now run the app, you should see the AHOY MAPKIT SDK initialisation successful message in the xcode console.

Display a Map

  • Open the info.plist and make sure you have location usage permissions by adding NSLocationWhenInUseUsageDescription key.

  • There are two ways of displaying a map on the ViewController

  • IBDesignable

  • Please note if your current ViewController is not the rootViewController(not the initial controller) of your app, only then you can use this option, becuase the AhoyMap SDK initialisation is an async process and you need to make sure AhoyMap is initialised, if your view controller is not the root view controller you can simply do these steps

  • Drag and drop a UIView on to the xib/storyboard

  • Select the Identity Inspector and set the Custom Class to AhoyMapView and module to AhoyMap

  • Create an @IBOutlet and link it to your ViewController

  • Programatically

  • if your ViewController where you intend to show Map is a rootViewController(initial view controller) you will have to post a notification from AhoySDKManagerDelegate’s didInitialiseAhoyMapKitSDK function to notify the ViewController about SDKs initialisation and then add the Map programatically, please have a look at the example apps implementation for more details.

let mapView = AhoyMapView()
mapView.frame = self.view.frame
mapContainerView.addSubview(mapView)

Add Polyline to the Map

  • Make sure you have added AhoyMapView either through IBDesignable or through code and add the following function
do {
    let geoCoordinatesArray = [
    CLLocationCoordinate2D(latitude: 25.308147142589714, longitude: 55.37651267478113),
    CLLocationCoordinate2D(latitude: 25.311452472079345, longitude: 55.379549601333615)
    ]
    polyline = Polyline(coordinates: geoCoordinatesArray, lineWidth: 30,         lineColor: .red)
    guard let polyline = polyline else {
        return
    }
    try ahoyMapView.addPolyLine(model: polyline)
} catch let error {
    print("could not add polyline \(error.localizedDescription)")
}
  • You should now see a polyline on your map passing through the given coordinates

Removing a polyline from the Map

  • Removing a polyline is fairly straight forward, we just need to make sure to pass the same model which was passed while adding the polyline
ahoyMapView.removePolyline(model: polyline)

Add Polygon to the Map

  • You can add a polygon on the map by using addPolyLine function of the AhoyMapView, sample implementation is as follows
let geoCoordinatesArray = [
CLLocationCoordinate2D(latitude: 25.30608803938275, longitude: 55.374215000171795),
CLLocationCoordinate2D(latitude: 25.308147142589714, longitude: 55.37651267478113),
CLLocationCoordinate2D(latitude: 25.311452472079345, longitude: 55.379549601333615)
]
let polygon = Polygon(coordinates: geoCoordinatesArray, color: .red)
do {
try mapView.addPolygon(polygon: polygon)
} catch let error {
print("could not add polygon \(error.localizedDescription)")
}

Remove a polygon from Map

  • Removing a polygon is fairly straight forward, we just need to make sure to pass the same model which was passed while adding the polygon

mapView.removePolygon(polygon: polygon)

Add Marker to the Map

  • The marker can be added to the map using the addMarker function of the AhoyMapView, the sample implementation is as follows.
let markerCoordinates = CLLocationCoordinate2D(latitude: 25.302506048147787, longitude: 55.375242494744285)
let marker = Marker(coordinates: test, image: UIImage(named: "pin"))
do {
    try mapView.addMarker(marker: marker)
} catch let error {
    print("error is \(error)")
}

Remove the marker

  • A marker can be removed from the map using the removeMarker function, we just need to make sure to pass the same model which was passed while adding the marker
mapView.removeMarker(marker: marker)

Set Zoom Level of Map

  • The Zoom level of map can be set within the range [0-22] using the setZoomLevel function
mapView.setZoomLevel(level: 22)

Toggle traffic flow on the Map

  • The traffic flow on the map can be enabled/disabled using the showTrafficFlow as follows
mapView.showTrafficFlow(isTrafficOn: true)

Show certain location on the Map

  • If you wanted to show a certain location on the map that can be done using the moveCamera function as follows
let locationCoordinates = CLLocationCoordinate2D(latitude: 25.302506048147787, longitude: 55.375242494744285)
mapView.moveCamera(coordinates: locationCoordinates)

Set Map Scheme for Map

  • AhoyMap supports wide range of map schemes those can be set using the setMapScheme as follows
mapView.setMapScheme(scheme: .satellite)

Gesture Recognizers

  • AhoyMaps supports 3 gestures Tap, Long Press and Pan gesture, all these are bundled together in a protocol AhoyMapViewGestureDelegate this protocol will have 3 functions which serves as call backs for each gesture

  • didFinishPanGesture will return the origin and the center coordinate of the MapView

  • didFinishLongPressGesture will return the coordinates of the long press location

  • didFinishTapGesture will return the coordinates of the tap location

  • The navigate feature of AhoyMaps SDK helps you in seamless integration of navigation functionality in no time, here is all you need to do to have the navigation feature up and running

  • Open your view controller and add the following

  • Show Swipe gesture based manoeuver for every new route instruction.


let destinationLocation = CLLocation(latitude: 25.327396542469668, longitude: 55.38771042802632)

AhoyMapManager.shared().launchAhoyMaps(destinationLocation: destinationLocation)

  • If you have a TripID, you can use it to restrict the user to follow your trip, the navigation feature with TripID can be integrated as follows
  • Show Swipe gesture based manoeuver for every new route instruction.

let currentTripId =  "Afisb6-3dfhr-hfghdgf-bdhfbi"

AhoyMapManager.shared().launchAhoyMaps(tripID: currentTripId)

Preview Map Routes to destination using coordinates

  • The map preview feature of AhoyMaps SDK helps you in seamless integration of route preview functionality in no time, here is all you need to do to have the preview route feature up and running

  • Open your view controller, create an instance of ahoy map view and add the following


let currentTripId =  "Afisb6-3dfhr-hfghdgf-bdhfbi"

AhoyMapManager.shared().launchAhoyMaps(tripID: currentTripId)

Preview Map Routes to destination using coordinates

  • The map preview feature of AhoyMaps SDK helps you in seamless integration of route preview functionality in no time, here is all you need to do to have the preview route feature up and running

  • Open your view controller, create an instance of ahoy map view and add the following


>>>>>>> 2ae8cb5dfd138d8afe36a8f4ae6368bbb63b5bd3
let destinationLocation = CLLocation(latitude: 25.327396542469668, longitude: 55.38771042802632)

ahoyMapView.createRoute(for: destinationLocation, isPedisterian: isPedisterian) { route in 
}
  

Preview Map Routes to destination using trip id

  • The map preview feature of AhoyMaps SDK helps you in seamless integration of route preview functionality in no time, here is all you need to do to have the preview route feature up and running

  • Open your view controller, create an instance of ahoy map view and add the following

let tripd: String = "ENTER YOUR TRIP ID HERE"
ahoyMapView.createRoute(for: tripd, isPedisterian: isPedisterian) { route in
    print("Trip id Route is \(route.lengthInMeters ?? -1)")
} failure: { [weak self] error in
}  

EXAMPLES

  • The Examples Apps with of all the AhoyMap functions can be downloaded through this, you will have to do a pod install and pass your subscription key in the AppDelegate to test. Link