├── 5n7jy.gif ├── README.md ├── maptest ├── Assets.xcassets │ ├── Contents.json │ ├── arrow.imageset │ │ ├── arrow.pdf │ │ └── Contents.json │ ├── earthfly.imageset │ │ ├── earthfly.gif │ │ └── Contents.json │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── ArrowOverlayRenderer.swift ├── AppDelegate.swift ├── HelperClass.swift └── ViewController.swift └── maptest.xcodeproj ├── xcuserdata └── abin.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── project.xcworkspace ├── contents.xcworkspacedata ├── xcuserdata │ └── abin.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcshareddata │ └── IDEWorkspaceChecks.plist └── project.pbxproj /5n7jy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin0992/AnimatedMapOverlay/HEAD/5n7jy.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text](https://github.com/abin0992/AnimatedMapOverlay/blob/master/5n7jy.gif?raw=true) 2 | -------------------------------------------------------------------------------- /maptest/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /maptest/Assets.xcassets/arrow.imageset/arrow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin0992/AnimatedMapOverlay/HEAD/maptest/Assets.xcassets/arrow.imageset/arrow.pdf -------------------------------------------------------------------------------- /maptest/Assets.xcassets/earthfly.imageset/earthfly.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin0992/AnimatedMapOverlay/HEAD/maptest/Assets.xcassets/earthfly.imageset/earthfly.gif -------------------------------------------------------------------------------- /maptest.xcodeproj/xcuserdata/abin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /maptest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /maptest.xcodeproj/project.xcworkspace/xcuserdata/abin.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin0992/AnimatedMapOverlay/HEAD/maptest.xcodeproj/project.xcworkspace/xcuserdata/abin.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /maptest/Assets.xcassets/arrow.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "arrow.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /maptest/Assets.xcassets/earthfly.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "earthfly.gif" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /maptest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /maptest.xcodeproj/xcuserdata/abin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | maptest.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /maptest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /maptest/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /maptest/ArrowOverlayRenderer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // arrowOverlay.swift 3 | // maptest 4 | // 5 | // Created by Abin Baby on 05/04/2018. 6 | // Copyright © 2018 Abin Baby. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | import MapKit 12 | 13 | class MapOverlayView: MKOverlayRenderer { 14 | 15 | var overlayImage: UIImage 16 | var angle: CGFloat 17 | 18 | init(overlay: MKOverlay, overlayImage:UIImage, angle: CGFloat) { 19 | self.overlayImage = overlayImage 20 | self.angle = angle 21 | super.init(overlay: overlay) 22 | } 23 | 24 | override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in context: CGContext) { 25 | 26 | let mapImage = overlayImage.cgImage 27 | let mapRect = rect(for: overlay.boundingMapRect) 28 | 29 | // Calculate centre point on which image should be rotated 30 | let centerPoint = CGPoint(x: mapRect.midX, y: mapRect.midY) 31 | 32 | let a = sqrt(pow(centerPoint.x, 2.0) + pow(centerPoint.y, 2.0)) 33 | 34 | let sub1 = (centerPoint.y / a) * cos(angle / 2.0) 35 | let sub2 = (centerPoint.x / a) * sin(angle / 2.0) 36 | let deltaX = -2 * a * sin((0 - angle) / 2.0) * (sub1 + sub2) 37 | 38 | let sub3 = (centerPoint.x / a) * cos(angle / 2.0) 39 | let sub4 = (centerPoint.y / a) * sin(angle / 2.0) 40 | let deltaY = 2 * a * sin((0 - angle) / 2.0) * (sub3 - sub4) 41 | 42 | context.translateBy(x: deltaX, y: deltaY) 43 | context.rotate(by: angle) 44 | context.draw(mapImage!, in: mapRect) 45 | } 46 | } 47 | 48 | 49 | class MapOverlay: NSObject, MKOverlay { 50 | 51 | var coordinate: CLLocationCoordinate2D 52 | var boundingMapRect: MKMapRect 53 | var identifier: String? 54 | 55 | init(identifier:String, coord: CLLocationCoordinate2D, rect: MKMapRect) { 56 | self.coordinate = coord 57 | self.boundingMapRect = rect 58 | self.identifier = identifier 59 | } 60 | } 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /maptest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /maptest/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // maptest 4 | // 5 | // Created by Abin Baby on 05/04/2018. 6 | // Copyright © 2018 Abin Baby. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /maptest/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /maptest/HelperClass.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HelperClass.swift 3 | // maptest 4 | // 5 | // Created by Abin Baby on 09/04/2018. 6 | // Copyright © 2018 Abin Baby. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import MapKit 11 | import UIKit 12 | 13 | class HelperClass { 14 | 15 | //MARK: get cordinates from line 16 | func getPointsOnRoute(from: CLLocation?, to: CLLocation?, on mapView: MKMapView?) -> [CLLocation]? { 17 | let NUMBER_OF_PIXELS_TO_SKIP: Int = 120 18 | //lower number will give a more smooth animation, but will result in more layers 19 | var ret = [Any]() 20 | 21 | var fromPoint: CGPoint? = nil 22 | if let aCoordinate = from?.coordinate { 23 | fromPoint = mapView?.convert(aCoordinate, toPointTo: mapView) 24 | } 25 | var toPoint: CGPoint? = nil 26 | if let aCoordinate = to?.coordinate { 27 | toPoint = mapView?.convert(aCoordinate, toPointTo: mapView) 28 | } 29 | let allPixels = getAllPoints(from: fromPoint!, to: toPoint!) 30 | var i = 0 31 | while i < (allPixels?.count)! { 32 | let pointVal = allPixels![i] as? NSValue 33 | ret.append(point(toLocation: mapView, from: (pointVal?.cgPointValue)!)!) 34 | i += NUMBER_OF_PIXELS_TO_SKIP 35 | } 36 | ret.append(point(toLocation: mapView, from: toPoint!)!) 37 | return ret as? [CLLocation] 38 | } 39 | 40 | 41 | /**convert a CGPoint to a CLLocation according to a mapView*/ 42 | func point(toLocation mapView: MKMapView?, from fromPoint: CGPoint) -> CLLocation? { 43 | let coord: CLLocationCoordinate2D? = mapView?.convert(fromPoint, toCoordinateFrom: mapView) 44 | return CLLocation(latitude: coord?.latitude ?? 0, longitude: coord?.longitude ?? 0) 45 | } 46 | 47 | func getAllPoints(from fPoint: CGPoint, to tPoint: CGPoint) -> [Any]? { 48 | /*Simplyfied implementation of Bresenham's line algoritme */ 49 | var ret = [AnyHashable]() 50 | let deltaX: Float = fabsf(Float(tPoint.x - fPoint.x)) 51 | let deltaY: Float = fabsf(Float(tPoint.y - fPoint.y)) 52 | var x: Float = Float(fPoint.x) 53 | var y: Float = Float(fPoint.y) 54 | var err: Float = deltaX - deltaY 55 | var sx: Float = -0.5 56 | var sy: Float = -0.5 57 | if fPoint.x < tPoint.x { 58 | sx = 0.5 59 | } 60 | if fPoint.y < tPoint.y { 61 | sy = 0.5 62 | } 63 | repeat { 64 | ret.append(NSValue(cgPoint: CGPoint(x: CGFloat(x), y: CGFloat(y)))) 65 | let e: Float = 2 * err 66 | if e > -deltaY { 67 | err -= deltaY 68 | x += sx 69 | } 70 | if e < deltaX { 71 | err += deltaX 72 | y += sy 73 | } 74 | } while round(Float(x)) != round(Float(tPoint.x)) && round(Float(y)) != round(Float(tPoint.y)) 75 | ret.append(NSValue(cgPoint: tPoint)) 76 | //add final point 77 | return ret 78 | } 79 | 80 | // MARK: direction of image annotation 81 | func DirectionBetweenPoints(previousMapPoint: MKMapPoint, nextMapPoint: MKMapPoint) -> CLLocationDirection { 82 | let x: Double = nextMapPoint.x - previousMapPoint.x 83 | let y: Double = nextMapPoint.y - previousMapPoint.y 84 | 85 | return fmod(RadiansToDegrees(radians: atan2(y, x)), 360.0) 86 | } 87 | 88 | func RadiansToDegrees(radians: Double) -> Double { 89 | return radians * 180.0 / .pi 90 | } 91 | 92 | func DegreesToRadians(degrees: Double) -> CGFloat { 93 | return CGFloat(degrees * .pi / 180.0) 94 | } 95 | 96 | func MKMapRectForCoordinateRegion(region:MKCoordinateRegion) -> MKMapRect { 97 | let topLeft = CLLocationCoordinate2D(latitude: region.center.latitude + (region.span.latitudeDelta/2), longitude: region.center.longitude - (region.span.longitudeDelta/2)) 98 | let bottomRight = CLLocationCoordinate2D(latitude: region.center.latitude - (region.span.latitudeDelta/2), longitude: region.center.longitude + (region.span.longitudeDelta/2)) 99 | 100 | let a = MKMapPointForCoordinate(topLeft) 101 | let b = MKMapPointForCoordinate(bottomRight) 102 | 103 | return MKMapRect(origin: MKMapPoint(x:min(a.x,b.x), y:min(a.y,b.y)), size: MKMapSize(width: abs(a.x-b.x), height: abs(a.y-b.y))) 104 | } 105 | 106 | open func middlePointOfListMarkers(listCoords: [CLLocationCoordinate2D]) -> CLLocationCoordinate2D{ 107 | 108 | var x = 0.0 as CGFloat 109 | var y = 0.0 as CGFloat 110 | var z = 0.0 as CGFloat 111 | 112 | for coordinate in listCoords{ 113 | 114 | let lat:CGFloat = DegreesToRadians(degrees: coordinate.latitude) 115 | let lon:CGFloat = DegreesToRadians(degrees: coordinate.longitude) 116 | 117 | x = x + cos(lat) * cos(lon) 118 | y = y + cos(lat) * sin(lon); 119 | z = z + sin(lat); 120 | 121 | } 122 | 123 | x = x/CGFloat(listCoords.count) 124 | y = y/CGFloat(listCoords.count) 125 | z = z/CGFloat(listCoords.count) 126 | 127 | let resultLon: CGFloat = atan2(y, x) 128 | let resultHyp: CGFloat = sqrt(x*x+y*y) 129 | let resultLat:CGFloat = atan2(z, resultHyp) 130 | 131 | let newLat = RadiansToDegrees(radians: Double(resultLat)) 132 | let newLon = RadiansToDegrees(radians: Double(resultLon)) 133 | let result:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: newLat, longitude: newLon) 134 | return result 135 | 136 | } 137 | 138 | //Calculate direction of polyline 139 | func calculateDirectionOfpolyline(coordinates: [CLLocationCoordinate2D]) -> CLLocationDirection { 140 | let first: MKMapPoint = MKMapPointForCoordinate(coordinates.first!) 141 | let last: MKMapPoint = MKMapPointForCoordinate(coordinates.last!) 142 | let arrowDirection: CLLocationDirection = DirectionBetweenPoints(previousMapPoint: first, nextMapPoint: last) 143 | return arrowDirection 144 | } 145 | 146 | func convertCLLocationCoordinate2DToCLLocation(LocationCoordinates: CLLocationCoordinate2D) -> CLLocation { 147 | let fLat: CLLocationDegrees = LocationCoordinates.latitude 148 | let fLon: CLLocationDegrees = LocationCoordinates.longitude 149 | let location: CLLocation = CLLocation(latitude: fLat, longitude: fLon) 150 | return location 151 | } 152 | 153 | func getEquidistantPoints(startPoint: CLLocationCoordinate2D, endPoint: CLLocationCoordinate2D, numberOfPoints: Int) -> [CLLocationCoordinate2D] { 154 | 155 | var midPoints: [CLLocationCoordinate2D] = [] 156 | var newPoint: CLLocationCoordinate2D = CLLocationCoordinate2DMake(0, 0) 157 | 158 | let count = numberOfPoints + 1 159 | 160 | let latitudeModifier = (endPoint.latitude - startPoint.latitude) / Double(count) 161 | let longitudeModifier = (endPoint.longitude - startPoint.longitude) / Double(count) 162 | 163 | // Loop through the points 164 | for i in 1.. MKOverlayRenderer { 64 | 65 | if overlay is MapOverlay { 66 | let angle: CGFloat = helperClass.DegreesToRadians(degrees: Double(arrowDirection)) 67 | let overlayView = MapOverlayView(overlay: overlay, overlayImage: arrowImage, angle: angle) 68 | return overlayView 69 | } 70 | else { 71 | guard let polyline = overlay as? MKPolyline else { 72 | fatalError("Not a MKPolyline") 73 | } 74 | let renderer = MKPolylineRenderer(polyline: polyline) 75 | 76 | renderer.strokeColor = #colorLiteral(red: 0.1764705926, green: 0.4980392158, blue: 0.7568627596, alpha: 1) 77 | renderer.lineWidth = 5 78 | renderer.alpha = 0.5 79 | return renderer 80 | } 81 | } 82 | 83 | func mapView(_ mapView: MKMapView, didAdd renderers: [MKOverlayRenderer]) { 84 | for renderer in renderers { 85 | if renderer is MapOverlayView { 86 | renderer.alpha = 0.0 87 | } 88 | } 89 | } 90 | 91 | 92 | // Toggle alpha value of MKOverlayRenderer 93 | @objc func toggle() { 94 | switch visibleOverlayLayer { 95 | case 1: 96 | visibleOverlayLayer = 2 97 | changeAlphaValue(identifier: "1") 98 | case 2: 99 | visibleOverlayLayer = 3 100 | changeAlphaValue(identifier: "2") 101 | case 3: 102 | visibleOverlayLayer = 1 103 | changeAlphaValue(identifier: "3") 104 | default: 105 | changeAlphaValue(identifier: "0") 106 | } 107 | } 108 | 109 | func changeAlphaValue(identifier: String) { 110 | let overlays = self.mapView.overlays 111 | let tag: String = identifier 112 | for overlay in overlays { 113 | if let overlay = overlay as? MapOverlay { 114 | let identifier = overlay.identifier 115 | if identifier == tag { 116 | let renderer = mapView.renderer(for: overlay) 117 | DispatchQueue.main.async{ 118 | renderer?.alpha = 1.0 119 | } 120 | } 121 | else { 122 | let renderer = mapView.renderer(for: overlay) 123 | DispatchQueue.main.async{ 124 | renderer?.alpha = 0.0 125 | } 126 | } 127 | } 128 | } 129 | } 130 | 131 | 132 | // Add first overlays to map 133 | func addLayersOfAnimatingOverlay() { 134 | let sourcePoint = helperClass.convertCLLocationCoordinate2DToCLLocation(LocationCoordinates: coordinates.first!) 135 | let destinationPoint = helperClass.convertCLLocationCoordinate2DToCLLocation(LocationCoordinates: coordinates.last!) 136 | pointsCoordinates1 = self.getLocationArrayFrom(startLocation: sourcePoint, endLocation: destinationPoint) 137 | //add overlay on above coordinates 138 | DispatchQueue.main.async{ 139 | self.addDirectionOverlayInMap(locationArray: self.pointsCoordinates1, title: "1") 140 | } 141 | visibleOverlayLayer = 1 142 | 143 | let fromPoints = helperClass.getEquidistantPoints(startPoint: pointsCoordinates1[0], endPoint: pointsCoordinates1[1], numberOfPoints: 2) 144 | let lastTwoPoints = pointsCoordinates1.suffix(2) 145 | print(lastTwoPoints) 146 | let toPoints = helperClass.getEquidistantPoints(startPoint: lastTwoPoints.first!, endPoint: lastTwoPoints.last!, numberOfPoints: 2) 147 | let from2 = helperClass.convertCLLocationCoordinate2DToCLLocation(LocationCoordinates: fromPoints[0]) 148 | let to2 = helperClass.convertCLLocationCoordinate2DToCLLocation(LocationCoordinates: toPoints[0]) 149 | pointsCoordinates2 = self.getLocationArrayFrom(startLocation: from2, endLocation: to2) 150 | DispatchQueue.main.async{ 151 | self.addDirectionOverlayInMap(locationArray: self.pointsCoordinates2, title: "2") 152 | } 153 | 154 | let from3 = helperClass.convertCLLocationCoordinate2DToCLLocation(LocationCoordinates: fromPoints[1]) 155 | let to3 = helperClass.convertCLLocationCoordinate2DToCLLocation(LocationCoordinates: toPoints[1]) 156 | pointsCoordinates3 = self.getLocationArrayFrom(startLocation: from3, endLocation: to3) 157 | DispatchQueue.main.async{ 158 | self.addDirectionOverlayInMap(locationArray: self.pointsCoordinates3, title: "3") 159 | } 160 | } 161 | 162 | //Add layers to map 163 | func getLocationArrayFrom(startLocation: CLLocation, endLocation: CLLocation) -> [CLLocationCoordinate2D] { 164 | var coordinatesArray: [CLLocationCoordinate2D] = [] 165 | if let points = helperClass.getPointsOnRoute(from: startLocation, to: endLocation, on: mapView) { 166 | for point in points { 167 | let coordinate = point.coordinate 168 | coordinatesArray.append(coordinate) 169 | } 170 | } 171 | return coordinatesArray 172 | } 173 | 174 | // Add overlays to map 175 | func addDirectionOverlayInMap(locationArray: [CLLocationCoordinate2D], title: String){ 176 | for pointsCoordinate in locationArray { 177 | let location = pointsCoordinate 178 | //1. Show direction Using Overlays 179 | let span = MKCoordinateSpanMake(1.0, 1.0) 180 | let region = MKCoordinateRegion(center: location, span: span) 181 | let mapRect: MKMapRect = helperClass.MKMapRectForCoordinateRegion(region: region) 182 | overlay = MapOverlay(identifier: title, coord: location, rect: mapRect) 183 | self.mapView.add(overlay) 184 | } 185 | } 186 | } 187 | 188 | -------------------------------------------------------------------------------- /maptest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 86215844207BB62200DA25F7 /* HelperClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86215843207BB62200DA25F7 /* HelperClass.swift */; }; 11 | 8639DC6220764C7700A45D1B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8639DC6120764C7700A45D1B /* AppDelegate.swift */; }; 12 | 8639DC6420764C7700A45D1B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8639DC6320764C7700A45D1B /* ViewController.swift */; }; 13 | 8639DC6720764C7700A45D1B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8639DC6520764C7700A45D1B /* Main.storyboard */; }; 14 | 8639DC6920764C7700A45D1B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8639DC6820764C7700A45D1B /* Assets.xcassets */; }; 15 | 8639DC6C20764C7700A45D1B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8639DC6A20764C7700A45D1B /* LaunchScreen.storyboard */; }; 16 | 86C853EA207674B800E781CE /* ArrowOverlayRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C853E9207674B800E781CE /* ArrowOverlayRenderer.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 86215843207BB62200DA25F7 /* HelperClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelperClass.swift; sourceTree = ""; }; 21 | 8639DC5E20764C7700A45D1B /* maptest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = maptest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 8639DC6120764C7700A45D1B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 8639DC6320764C7700A45D1B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 8639DC6620764C7700A45D1B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 8639DC6820764C7700A45D1B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 8639DC6B20764C7700A45D1B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 8639DC6D20764C7700A45D1B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 86C853E9207674B800E781CE /* ArrowOverlayRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowOverlayRenderer.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 8639DC5B20764C7700A45D1B /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 8639DC5520764C7700A45D1B = { 43 | isa = PBXGroup; 44 | children = ( 45 | 8639DC6020764C7700A45D1B /* maptest */, 46 | 8639DC5F20764C7700A45D1B /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 8639DC5F20764C7700A45D1B /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 8639DC5E20764C7700A45D1B /* maptest.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 8639DC6020764C7700A45D1B /* maptest */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 8639DC6120764C7700A45D1B /* AppDelegate.swift */, 62 | 86215843207BB62200DA25F7 /* HelperClass.swift */, 63 | 8639DC6320764C7700A45D1B /* ViewController.swift */, 64 | 8639DC6520764C7700A45D1B /* Main.storyboard */, 65 | 8639DC6820764C7700A45D1B /* Assets.xcassets */, 66 | 8639DC6A20764C7700A45D1B /* LaunchScreen.storyboard */, 67 | 8639DC6D20764C7700A45D1B /* Info.plist */, 68 | 86C853E9207674B800E781CE /* ArrowOverlayRenderer.swift */, 69 | ); 70 | path = maptest; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | 8639DC5D20764C7700A45D1B /* maptest */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = 8639DC7020764C7700A45D1B /* Build configuration list for PBXNativeTarget "maptest" */; 79 | buildPhases = ( 80 | 8639DC5A20764C7700A45D1B /* Sources */, 81 | 8639DC5B20764C7700A45D1B /* Frameworks */, 82 | 8639DC5C20764C7700A45D1B /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = maptest; 89 | productName = maptest; 90 | productReference = 8639DC5E20764C7700A45D1B /* maptest.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | 8639DC5620764C7700A45D1B /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | LastSwiftUpdateCheck = 0920; 100 | LastUpgradeCheck = 0920; 101 | ORGANIZATIONNAME = "Abin Baby"; 102 | TargetAttributes = { 103 | 8639DC5D20764C7700A45D1B = { 104 | CreatedOnToolsVersion = 9.2; 105 | ProvisioningStyle = Automatic; 106 | }; 107 | }; 108 | }; 109 | buildConfigurationList = 8639DC5920764C7700A45D1B /* Build configuration list for PBXProject "maptest" */; 110 | compatibilityVersion = "Xcode 8.0"; 111 | developmentRegion = en; 112 | hasScannedForEncodings = 0; 113 | knownRegions = ( 114 | en, 115 | Base, 116 | ); 117 | mainGroup = 8639DC5520764C7700A45D1B; 118 | productRefGroup = 8639DC5F20764C7700A45D1B /* Products */; 119 | projectDirPath = ""; 120 | projectRoot = ""; 121 | targets = ( 122 | 8639DC5D20764C7700A45D1B /* maptest */, 123 | ); 124 | }; 125 | /* End PBXProject section */ 126 | 127 | /* Begin PBXResourcesBuildPhase section */ 128 | 8639DC5C20764C7700A45D1B /* Resources */ = { 129 | isa = PBXResourcesBuildPhase; 130 | buildActionMask = 2147483647; 131 | files = ( 132 | 8639DC6C20764C7700A45D1B /* LaunchScreen.storyboard in Resources */, 133 | 8639DC6920764C7700A45D1B /* Assets.xcassets in Resources */, 134 | 8639DC6720764C7700A45D1B /* Main.storyboard in Resources */, 135 | ); 136 | runOnlyForDeploymentPostprocessing = 0; 137 | }; 138 | /* End PBXResourcesBuildPhase section */ 139 | 140 | /* Begin PBXSourcesBuildPhase section */ 141 | 8639DC5A20764C7700A45D1B /* Sources */ = { 142 | isa = PBXSourcesBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | 86C853EA207674B800E781CE /* ArrowOverlayRenderer.swift in Sources */, 146 | 8639DC6420764C7700A45D1B /* ViewController.swift in Sources */, 147 | 86215844207BB62200DA25F7 /* HelperClass.swift in Sources */, 148 | 8639DC6220764C7700A45D1B /* AppDelegate.swift in Sources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXSourcesBuildPhase section */ 153 | 154 | /* Begin PBXVariantGroup section */ 155 | 8639DC6520764C7700A45D1B /* Main.storyboard */ = { 156 | isa = PBXVariantGroup; 157 | children = ( 158 | 8639DC6620764C7700A45D1B /* Base */, 159 | ); 160 | name = Main.storyboard; 161 | sourceTree = ""; 162 | }; 163 | 8639DC6A20764C7700A45D1B /* LaunchScreen.storyboard */ = { 164 | isa = PBXVariantGroup; 165 | children = ( 166 | 8639DC6B20764C7700A45D1B /* Base */, 167 | ); 168 | name = LaunchScreen.storyboard; 169 | sourceTree = ""; 170 | }; 171 | /* End PBXVariantGroup section */ 172 | 173 | /* Begin XCBuildConfiguration section */ 174 | 8639DC6E20764C7700A45D1B /* Debug */ = { 175 | isa = XCBuildConfiguration; 176 | buildSettings = { 177 | ALWAYS_SEARCH_USER_PATHS = NO; 178 | CLANG_ANALYZER_NONNULL = YES; 179 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 180 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 181 | CLANG_CXX_LIBRARY = "libc++"; 182 | CLANG_ENABLE_MODULES = YES; 183 | CLANG_ENABLE_OBJC_ARC = YES; 184 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_COMMA = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 189 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 190 | CLANG_WARN_EMPTY_BODY = YES; 191 | CLANG_WARN_ENUM_CONVERSION = YES; 192 | CLANG_WARN_INFINITE_RECURSION = YES; 193 | CLANG_WARN_INT_CONVERSION = YES; 194 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 195 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 197 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 198 | CLANG_WARN_STRICT_PROTOTYPES = YES; 199 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 200 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 201 | CLANG_WARN_UNREACHABLE_CODE = YES; 202 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 203 | CODE_SIGN_IDENTITY = "iPhone Developer"; 204 | COPY_PHASE_STRIP = NO; 205 | DEBUG_INFORMATION_FORMAT = dwarf; 206 | ENABLE_STRICT_OBJC_MSGSEND = YES; 207 | ENABLE_TESTABILITY = YES; 208 | GCC_C_LANGUAGE_STANDARD = gnu11; 209 | GCC_DYNAMIC_NO_PIC = NO; 210 | GCC_NO_COMMON_BLOCKS = YES; 211 | GCC_OPTIMIZATION_LEVEL = 0; 212 | GCC_PREPROCESSOR_DEFINITIONS = ( 213 | "DEBUG=1", 214 | "$(inherited)", 215 | ); 216 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 217 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 218 | GCC_WARN_UNDECLARED_SELECTOR = YES; 219 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 220 | GCC_WARN_UNUSED_FUNCTION = YES; 221 | GCC_WARN_UNUSED_VARIABLE = YES; 222 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 223 | MTL_ENABLE_DEBUG_INFO = YES; 224 | ONLY_ACTIVE_ARCH = YES; 225 | SDKROOT = iphoneos; 226 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 227 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 228 | }; 229 | name = Debug; 230 | }; 231 | 8639DC6F20764C7700A45D1B /* Release */ = { 232 | isa = XCBuildConfiguration; 233 | buildSettings = { 234 | ALWAYS_SEARCH_USER_PATHS = NO; 235 | CLANG_ANALYZER_NONNULL = YES; 236 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 237 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 238 | CLANG_CXX_LIBRARY = "libc++"; 239 | CLANG_ENABLE_MODULES = YES; 240 | CLANG_ENABLE_OBJC_ARC = YES; 241 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 242 | CLANG_WARN_BOOL_CONVERSION = YES; 243 | CLANG_WARN_COMMA = YES; 244 | CLANG_WARN_CONSTANT_CONVERSION = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INFINITE_RECURSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 252 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 253 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 254 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 255 | CLANG_WARN_STRICT_PROTOTYPES = YES; 256 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 257 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 258 | CLANG_WARN_UNREACHABLE_CODE = YES; 259 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 260 | CODE_SIGN_IDENTITY = "iPhone Developer"; 261 | COPY_PHASE_STRIP = NO; 262 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 263 | ENABLE_NS_ASSERTIONS = NO; 264 | ENABLE_STRICT_OBJC_MSGSEND = YES; 265 | GCC_C_LANGUAGE_STANDARD = gnu11; 266 | GCC_NO_COMMON_BLOCKS = YES; 267 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 268 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 269 | GCC_WARN_UNDECLARED_SELECTOR = YES; 270 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 271 | GCC_WARN_UNUSED_FUNCTION = YES; 272 | GCC_WARN_UNUSED_VARIABLE = YES; 273 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 274 | MTL_ENABLE_DEBUG_INFO = NO; 275 | SDKROOT = iphoneos; 276 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 277 | VALIDATE_PRODUCT = YES; 278 | }; 279 | name = Release; 280 | }; 281 | 8639DC7120764C7700A45D1B /* Debug */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 285 | CODE_SIGN_STYLE = Automatic; 286 | INFOPLIST_FILE = maptest/Info.plist; 287 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 288 | PRODUCT_BUNDLE_IDENTIFIER = riskmethods.maptest; 289 | PRODUCT_NAME = "$(TARGET_NAME)"; 290 | SWIFT_VERSION = 4.0; 291 | TARGETED_DEVICE_FAMILY = "1,2"; 292 | }; 293 | name = Debug; 294 | }; 295 | 8639DC7220764C7700A45D1B /* Release */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 299 | CODE_SIGN_STYLE = Automatic; 300 | INFOPLIST_FILE = maptest/Info.plist; 301 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 302 | PRODUCT_BUNDLE_IDENTIFIER = riskmethods.maptest; 303 | PRODUCT_NAME = "$(TARGET_NAME)"; 304 | SWIFT_VERSION = 4.0; 305 | TARGETED_DEVICE_FAMILY = "1,2"; 306 | }; 307 | name = Release; 308 | }; 309 | /* End XCBuildConfiguration section */ 310 | 311 | /* Begin XCConfigurationList section */ 312 | 8639DC5920764C7700A45D1B /* Build configuration list for PBXProject "maptest" */ = { 313 | isa = XCConfigurationList; 314 | buildConfigurations = ( 315 | 8639DC6E20764C7700A45D1B /* Debug */, 316 | 8639DC6F20764C7700A45D1B /* Release */, 317 | ); 318 | defaultConfigurationIsVisible = 0; 319 | defaultConfigurationName = Release; 320 | }; 321 | 8639DC7020764C7700A45D1B /* Build configuration list for PBXNativeTarget "maptest" */ = { 322 | isa = XCConfigurationList; 323 | buildConfigurations = ( 324 | 8639DC7120764C7700A45D1B /* Debug */, 325 | 8639DC7220764C7700A45D1B /* Release */, 326 | ); 327 | defaultConfigurationIsVisible = 0; 328 | defaultConfigurationName = Release; 329 | }; 330 | /* End XCConfigurationList section */ 331 | }; 332 | rootObject = 8639DC5620764C7700A45D1B /* Project object */; 333 | } 334 | --------------------------------------------------------------------------------