1 Reply
      Latest reply on Oct 8, 2019 7:54 AM by MarcoKat
      advancecoder Level 1 Level 1 (0 points)

        ViewController.swift

         

        import UIKit
        import MapKit
        
        class ViewController: UIViewController {
        
            @IBOutlet weak var mapView: MKMapView!
            
            let regionRadius: CLLocationDistance = 1000
            let initiallocation = CLLocation(latitude: 34.0522, longitude: 118.2437)
            
            func centerMapOnLocation(location: CLLocation)
            {
                let coordinateRegion = MKCoordinateRegion(center: location.coordinate, latitudinalMeters: regionRadius, longitudinalMeters: regionRadius)
                mapView.setRegion(coordinateRegion, animated: true)
                
            }
            
            override func viewDidLoad() {
                super.viewDidLoad()
                
                mapView.delegate = self
                
                centerMapOnLocation(location: initiallocation)
                
                
                
                let place = Place(title: "My House", locationName: "Shyamal's House", coordinate2D: CLLocationCoordinate2D(latitude: 37.3769993, longitude: -94.6895241), article: "Shyamal's Favorite Place to B-Ball", similarPlaces: [])
                
                mapView.addAnnotation(place)
                
                
                
            }
        
        }
        
        extension ViewController: MKMapViewDelegate {
            func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
                guard let annotation = annotation as? Place else {return nil}
                let identifier = "marker"
                var view: MKMarkerAnnotationView
                
                if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as Optional {
                    dequeuedView.annotation = annotation
                    view = dequeuedView as! MKMarkerAnnotationView
                } else {
                    view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
                    view.canShowCallout = true
                    view.calloutOffset = CGPoint(x: -5, y: 3)
                    view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
                }
                return view
            }
        }
        
        

         

        Place.swift

         

        import Foundation
        import MapKit
        
        class Place: NSObject, MKAnnotation {
            var coordinate: CLLocationCoordinate2D
            
            var title: String?
            var locationName: String?
            var coordinate2D: CLLocationCoordinate2D?
            var article: String?
            var similarPlaces: [CLLocationCoordinate2D]?
            
            init(title: String, locationName: String, coordinate2D: CLLocationCoordinate2D, article: String, similarPlaces: [CLLocationCoordinate2D]) {
                
                self.title = title
                self.locationName = locationName
                self.coordinate2D = coordinate2D
                self.article = article
                self.similarPlaces = similarPlaces
                self.coordinate = coordinate2D
                
                super.init()
                
            }
            /*
            init? (json: [Any]){
                //To be Completed
                super.init()
            }
            */
            
            var subtitle: String? {
                return locationName
            }
        }
        
        

         

        Output (console) at runtime:

         

        2019-09-25 09:28:05.596379-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [User Defaults] Couldn't write values for keys (
            ApplicationAccessibilityEnabled
        ) in CFPrefsPlistSource<0x600002c0aa80> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: Yes): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
        2019-09-25 09:28:05.598361-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [User Defaults] Couldn't write values for keys (
            AccessibilityEnabled
        ) in CFPrefsPlistSource<0x600002c0aa80> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
        2019-09-25 09:28:05.598762-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [User Defaults] Couldn't write values for keys (
            FullKeyboardAccessFocusRingEnabled
        ) in CFPrefsPlistSource<0x600002c0aa80> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
        2019-09-25 09:28:05.602326-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [User Defaults] Couldn't write values for keys (
            ApplicationAccessibilityEnabled
        ) in CFPrefsPlistSource<0x600002c0aa80> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
        2019-09-25 09:28:05.622810-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXAppAccessibility] AXSettingsLoader told to start
        2019-09-25 09:28:05.771522-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXLoading] Accessibility Started
        2019-09-25 09:28:05.772208-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXLoading] Accessibility Started (Mini-Server)
        2019-09-25 09:28:05.772247-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXLoading] Accessibility Initialize Runtime Overrides
        2019-09-25 09:28:05.776147-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXLoading] Accessibility Initialize Subclass Runtime Overrides (UIKit)
        2019-09-25 09:28:05.792909-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXAppAccessibility] Started AXRuntime server. SystemApp=0
        2019-09-25 09:28:05.837823-0500 Primary Operations - Geography Edition (iOS)[2661:83671] Metal API Validation Enabled
        2019-09-25 09:28:06.515178-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKApplicationStateMonitor] Observer count increased to 1
        2019-09-25 09:28:06.515236-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKApplicationStateMonitor] Will start monitoring using UIApplicationState with initial state (inBackground:YES, active:NO)
        2019-09-25 09:28:06.515440-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKLocationManager] Setting location provider [MKCoreLocationProvider](0x600002920850) for 0x10800aba0
        2019-09-25 09:28:06.515471-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKLocationManager] Shared location manager: 0x10800aba0
        2019-09-25 09:28:06.515910-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKApplicationStateMonitor] Observer count increased to 2
        2019-09-25 09:28:06.862886-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKApplicationStateMonitor] Will exit background
        2019-09-25 09:28:06.870600-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKApplicationStateMonitor] Will become active
        2019-09-25 09:28:07.311654-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset compass from edges 12
        2019-09-25 09:28:07.311985-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset legal attribution from corner 4
        2019-09-25 09:28:07.312214-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset compass from edges 12
        2019-09-25 09:28:07.312451-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset legal attribution from corner 4
        2019-09-25 09:28:07.312760-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset compass from edges 12
        2019-09-25 09:28:07.313020-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset legal attribution from corner 4
        2019-09-25 09:28:07.425405-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset compass from edges 12
        2019-09-25 09:28:07.425729-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset legal attribution from corner 4
        2019-09-25 09:28:07.425930-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset compass from edges 12
        2019-09-25 09:28:07.426163-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MapView] Could not inset legal attribution from corner 4
        2019-09-25 09:28:07.432164-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXAppAccessibility] Loading settings loader: (system: 0)
        2019-09-25 09:28:07.478129-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [UIAutomation] View did appear: <Primary_Operations___Geography_Edition__iOS_.ViewController: 0x10811fbf0> 0
        2019-09-25 09:28:07.478394-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXAppAccessibility] AXSettingsLoader told to start
        2019-09-25 09:28:07.478464-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXAppAccessibility] AXSettingsLoader told to start
        2019-09-25 09:28:07.478521-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXAppAccessibility] AXSettingsLoader told to start
        2019-09-25 09:28:09.250869-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [AXLoading] Posted kAXAccessibilityLoaded notification
        2019-09-25 09:28:12.622951-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKApplicationStateMonitor] Will resign active
        2019-09-25 09:28:12.623248-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] -[UIApplication _beginBackgroundTaskWithName:expirationHandler:]: Will add backgroundTask with taskName: com.apple.asset_manager.cache_resource_cleanup, expirationHandler: <__NSStackBlock__: 0x7ffeefbf9568>
        2019-09-25 09:28:12.623289-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] _UIBackgroundTaskInfo *_addBackgroundTask(NSString *__strong, void (^__strong)(void)): Created background task <_UIBackgroundTaskInfo: 0x600000cf4c90>: taskID = 0, taskName = com.apple.asset_manager.cache_resource_cleanup, count = 1, assertion = (null). Assertion will be assigned soon
        2019-09-25 09:28:12.623338-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] _UIBackgroundTaskInfo *_addBackgroundTask(NSString *__strong, void (^__strong)(void))_block_invoke: Creating new assertion since assertion is nil
        2019-09-25 09:28:12.623443-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] _UIBackgroundTaskInfo *_addBackgroundTask(NSString *__strong, void (^__strong)(void))_block_invoke: Created new assertion <BKSProcessAssertion: 0x600002171720>
        2019-09-25 09:28:12.688465-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] -[UIApplication _endBackgroundTask:]: Ending background task with UIBackgroundTaskIdentifier: 1
        2019-09-25 09:28:12.688562-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] -[UIApplication _endBackgroundTask:]: Ending task with identifier 1 and description: <_UIBackgroundTaskInfo: 0x600000cf4c90>: taskID = 1, taskName = com.apple.asset_manager.cache_resource_cleanup, count = 1, assertion = <BKSProcessAssertion: 0x600002171720>, _expireHandler: <__NSMallocBlock__: 0x600000cf4cc0>
        2019-09-25 09:28:12.688599-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] -[UIApplication _endBackgroundTask:]_block_invoke: Decrementing reference count for assertion used by background task with identifier 1: <_UIBackgroundTaskInfo: 0x600000cf4c90>: taskID = 1, taskName = com.apple.asset_manager.cache_resource_cleanup, count = 1, assertion = (null)
        2019-09-25 09:28:12.688625-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [BackgroundTask] -[UIApplication _endBackgroundTask:]_block_invoke: Will invalidate assertion: <BKSProcessAssertion: 0x600002171720> for task identifier: 1
        2019-09-25 09:28:12.688849-0500 Primary Operations - Geography Edition (iOS)[2661:83671] [MKApplicationStateMonitor] Will enter background
        2019-09-25 09:28:12.971093-0500 Primary Operations - Geography Edition (iOS)[2661:83671] Lifecycle: Task count reached zero, notifying AppKit side.