# Assignment 4: Documents and a SwiftUI Map v1.1.1 ## Goals Learn to use: - SwiftUI Map - Core Location - Core Data You will build a biking or running GPS tracker app that saves and displays tracks by browsing the local core data. We have posted a demo video of the app titled "assign4.mov" on Canvas. ## Tasks The following is a suggested series of steps for you to take, together with approximate points that each step will be worth. You can ignore all this and just emulate the demo video. Doing that gets you full points. However, the following set of steps is a good approach to building this app methodically. ## Step 1: Showing a Map and Tracking the Rider (25 pts) Go through the video on 10/26 for Core Location and using the SwiftUI Map object. Display the static location of the user on a map. Core data was discussed 10/14 and 10/19. Note that **you must display your map with `Map()`**, not `MKMapView()`. Use the appropriate user tracking parameter with your map initialization to track the rider smoothly. ## Step 2: Drawing the Path Trajectory (25 pts) - At each call of your `locationManager(manager:, didUpdateLocations:)`, you will be given an array of one or more `CLLocation`s. Draw the trajectory of all the points given in this call. - In the demo video, we implemented this using annotations. Feel free to use any method you deem appropriate. You will receive most of the credit as long as the view indicates the taken path and looks decent. You will get more points if you are able to use a `polyline` overlay over the `Map` object. ## Step 3: Saving Tracks (25 pts) You should have at least two tabs in your app, one for the recording map and one for displaying the set of saved tracks from CoreData. When the user stop recording and/or "saves", you must save the track to `CoreData`, programmatically moving to the saved tracks tab. Define a core data `Track` entity that contains, at a minimum, a name, a timestamp, and a sequence of coordinates. You could create multiple entity types, such as a *Track* and a *Point*, and then establish relationships between them (full credit). It is also acceptable to serialize the set of points as a JSON, and represent that in the Track as "binary data" (-3 pts). ## Step 4: Track Tab (25 pts) This tab should show all saved tracks, allow deleting of individual tracks with swipe left, and use navigation links to display individual tracks when selected. See the video. ## Hints: - You can use the simple format specified below to store each track. ``` struct GPXPoint: Codable { var latitude: Double var longitude: Double var altitude: Double var time: Date } struct GPXSegment: Codable { var coords : [GPXPoint] } struct GPXTrack : Codable { var name : String var link : String var time : String var segments : [GPXSegment] = [] var distance = "-" var feetClimbed = "-" } ``` - The `Map` view, like all views, is a `struct`. Core location requires a class instance, so you will have to have a class instancs that exports location info through bound variables. - Make sure you have added the required entry to the Info.plist file. Your app will require entries for accessing location data. ## Notes: **Important**: Please avoid the usage of UIKit, MKMapView or any UIKit views such as UIViewRepresentable. Using such packages would result in an automatic 0 in the respective task. You should *not* use **MKMapView()**. Instead, use **Map()**. - Might look [here]() for polygons. I have *not* verified this, might cause your laptop to go up in a puff of smoke, work great, or fail to compile. ## Video of example app [video](assign4.mp4)