{"id":3085,"date":"2020-10-01T15:09:38","date_gmt":"2020-10-01T15:09:38","guid":{"rendered":"http:\/\/4310.mynmi.net\/?page_id=3085"},"modified":"2026-04-23T21:20:48","modified_gmt":"2026-04-23T21:20:48","slug":"map-it","status":"publish","type":"page","link":"https:\/\/nmi.cool\/appdev\/map-it\/","title":{"rendered":"Homework 10: Map it!"},"content":{"rendered":"<!--\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/nmi.cool\/appdev\/wp-content\/uploads\/sites\/10\/2020\/10\/img_5f75fc580ce24.png\" alt=\"Google Maps: right-click a location to see coordinates with What's here?\"\/><\/figure>\n wp:paragraph -->\n<p>In this assignment, you&#8217;ll build a map-based app that lets users navigate to several locations. Each link passes latitude, longitude, and a map type to a shared <code>MapView<\/code> struct, updating the map display on each tap. If you need a refresher on how navigation links work, <a href=\"https:\/\/nmi.cool\/appdev\/anatomy-of-a-link\/\">review the Anatomy of a Link page<\/a>.<\/p>\n<!-- \/wp:post-content -->\n\n\n\n<!-- wp:heading {\"level\":2} -->\n<h2 class=\"wp-block-heading\">Demo<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:video {\"id\":3088} -->\n<figure class=\"wp-block-video\"><video controls aria-label=\"SwiftUI simulator demo: a completed MapKit integration displaying an interactive map with a location pin\" src=\"https:\/\/nmi.cool\/appdev\/wp-content\/uploads\/sites\/17\/2020\/10\/map.mp4\"><\/video><\/figure>\n<!-- \/wp:video -->\n\n<!-- wp:paragraph -->\n<p><em>Video: A screen recording of the iOS Simulator showing the finished Map It app. An interactive map fills the screen with a pin placed at a specific location, demonstrating the completed MapKit integration.<\/em><\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading {\"level\":2} -->\n<h2 class=\"wp-block-heading\">Get Started<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:list {\"ordered\":true} -->\n<ol class=\"wp-block-list\"><!-- wp:list-item --><li>Create a new Xcode project named <strong>MapProject<\/strong> (or something similar).<\/li><!-- \/wp:list-item -->\n<!-- wp:list-item --><li>Create a new SwiftUI file. Name it exactly <strong>MapView<\/strong> \u2014 spelling and capitalization matter here.<\/li><!-- \/wp:list-item -->\n<!-- wp:list-item --><li>Replace everything in <code>MapView.swift<\/code> with the code below. Do not modify it yet \u2014 just get it compiling first.<\/li><!-- \/wp:list-item --><\/ol>\n<!-- \/wp:list -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>import SwiftUI\nimport MapKit\n\nstruct MapView: UIViewRepresentable {\n    var thelat = Double()\n    var thelong = Double()\n    var pickMap = Int()\n    var whichMap = [MKMapType.standard, MKMapType.hybrid, MKMapType.satellite]\n\n    func makeUIView(context: Context) -> MKMapView {\n        MKMapView(frame: .zero)\n    }\n\n    func updateUIView(_ uiView: MKMapView, context: Context) {\n        let coordinate = CLLocationCoordinate2D(\n            latitude: thelat,\n            longitude: thelong)\n        let span = MKCoordinateSpan(latitudeDelta: 0.0002, longitudeDelta: 0.0002)\n        let region = MKCoordinateRegion(center: coordinate, span: span)\n        uiView.setRegion(region, animated: true)\n        uiView.mapType = whichMap[pickMap]\n    }\n}\n\n#Preview {\n    MapView(thelat: 34.011286, thelong: -116.166868)\n}<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:heading {\"level\":2} -->\n<h2 class=\"wp-block-heading\">Your Tasks<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p><strong>Task 1: Three sets of three links.<\/strong> In <code>ContentView<\/code>, create 9 navigation links total \u2014 three sets of three, each set pointing to a different real-world location. Each link passes three values to <code>MapView<\/code>: the latitude, the longitude, and a <code>pickMap<\/code> value (0, 1, or 2). Within each set, the three links should display the same location in standard, hybrid, and satellite map views respectively.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>To find coordinates: open the location in Google Maps in your browser, right-click it, and choose <em>What&#8217;s here?<\/em> \u2014 the latitude and longitude appear at the bottom of the screen. Include the negative sign if present.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>Task 2: Zoom level variables.<\/strong> Add two new variables to <code>MapView<\/code> for <code>latitudeDelta<\/code> and <code>longitudeDelta<\/code> (currently hardcoded to <code>0.0002<\/code>). Once the variables exist, update your links in <code>ContentView<\/code> to pass different values to them \u2014 so each link can show a different-sized area of the map.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>Task 3: Navigation title.<\/strong> Add a <code>NavigationView<\/code> to <code>ContentView<\/code> and apply a <code>.navigationTitle<\/code> modifier to each map page so each location is clearly labeled when you navigate to it.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>Task 4: Styled, extracted links.<\/strong> Style your 9 links to look great, then extract the link styling into a reusable view struct with variables \u2014 just as you did with extracted views earlier in the course. Each link should use the same extracted view, with variables controlling the label, coordinates, and map type. If you&#8217;ve updated to Xcode 16 or newer, use <em>Refactor \u2192 Extract Selection to File<\/em> instead of the old Extract to Subview option. You&#8217;ll then need to add <code>import SwiftUI<\/code>, a proper struct declaration, and a <code>var body: some View<\/code>.<\/p>\n<!-- \/wp:paragraph -->","protected":false},"excerpt":{"rendered":"<p>In this assignment, you&#8217;ll build a map-based app that lets users navigate to several locations. Each link passes latitude, longitude, and a map type to a shared MapView struct, updating the map display on each tap. If you need a refresher on how navigation links work, review the Anatomy of a Link page. Demo Video: &hellip; <a href=\"https:\/\/nmi.cool\/appdev\/map-it\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Homework 10: Map it!<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3085","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages\/3085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/comments?post=3085"}],"version-history":[{"count":18,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages\/3085\/revisions"}],"predecessor-version":[{"id":4266,"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/pages\/3085\/revisions\/4266"}],"wp:attachment":[{"href":"https:\/\/nmi.cool\/appdev\/wp-json\/wp\/v2\/media?parent=3085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}