EPISODE DOWNLOAD:

The rise of smartphones with accurate location and map services changes everything.

It literally changes the way we travel – you can book hotel with your phone via Airbnb based on your location. It changes the way you commute – now we don’t have to own a car but can call up one via Uber or Left anytime, having turn-by-turn direction. It gives parents the power of certainty when their children walk back home, knowing where they are.

As a developer, you may need to use Map sometimes in your app. In iOS and Swift, we use MapKit to do everything Map.

This is how the app will work:
1. It loads up data of a bunch of Starbucks Coffee shops in Sanfranciso from a JSON file.
2. It parses JSON data into foundation objects using SwiftyJSON.
3. Show the coffee shop on the map with annotation.
4. Get the user’s current location and show on the map
5. Tap on a location’s annotation, we are directed to Apple Maps app to have turn-by-turn direction from our current location to the coffee shop.

There’s a lot of works ahead. It’ll be fun! Let’s first download your starter project below:

EPISODE DOWNLOAD:

*********
ABOUT CODE MASTERY
*********
Code Mastery is hosted by Duc Tran, founder of Developers Academy.

This is his free-style no notes, no teleprompter presentation and live coding broadcast with you guys everyday.

To join Duc’s free courses, register for free at

*********
MEET DUC TRAN
*********

Duc Tran is founder of Developers Academy, one of the world’s leading iOS, Android and Web development trainers.

More than 2,000,000 developers have studied his video trainings; 100,000 developers see his posts each month. Each year, Duc has helped 20,000 plus developers graduate from his online courses or video series.

*********
FREE TRAININGS IN IOS DEVELOPMENT
*********
To subscribe and get free tutorials, courses and weekly content, visit me at:
Connect with Duc on facebook:
Tweet him:
Get daily inspiration:

===========
CODE IN THIS COURSE
===========

import UIKit
import MapKit
import SwiftyJSON

class ViewController: UIViewController
{
@IBOutlet weak var mapView: MKMapView!

// 13 store and load artworks
var venues = [Venue]()
func loadInitialData()
{
let fileName = Bundle.main.path(forResource: “Venues”, ofType: “json”)
let filePath = URL(fileURLWithPath: fileName!)
var data: Data?
do {
data = try Data(contentsOf: filePath, options: Data.ReadingOptions(rawValue: 0))
} catch let error {
data = nil
print(error.localizedDescription)
}

if let jsonData = data {
let json = JSON(data: jsonData)
if let venueJSONs = json[“response”][“venues”].array {
print(venueJSONs)
for venueJSON in venueJSONs {
if let venue = Venue.from(json: venueJSON) {
self.venues.append(venue)
}
}
}
}
}

// 15 ask user for current location
var locationManager = CLLocationManager()
func checkLocationAuthorizationStatus() {
locationManager.delegate = self
if CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
mapView.showsUserLocation = true
} else {
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
}

// 15
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
checkLocationAuthorizationStatus()
// 16 – Info.plist NSLOcationWhenInUseUsageDescription
}

override func viewDidLoad() {
super.viewDidLoad()

// 1 set initial location with a latitude and longitude
let initalLocation = CLLocation(latitude: 37.7749, longitude: -122.431297)

DOWNLOAD FULL SOURCE CODE:

Tags:
mapkit, mapkit swift, mapkit swift tutorial, mkmapview, mkmapview swift, mkmapview zoom to location, mkmapview custom annotation view, mkmapview directions between two points, mapkit directions swift, mapkit iOS, mapkit overlay, Duc tran, duc tran ios, developers academy, swiftyjson, parse json in iOS, json, swiftyjson, swiftyjson tableview, swiftyjson map