Map earthquake data in Swift Playgrounds

Map earthquake data in Swift Playgrounds


Swift Playgrounds has lots of powerful libraries available to allow students to explore all sorts of projects.  One of these frameworks is MapKit.  MapKit allows students to display map or satellite imagery directly into their program and call out points of interest.

The example below shows how students can very easily show satellite imagery of Indonesia and then plot points of interest such as the epicentre for recent earthquakes in Lombok.

To start experimenting with MapKit start with a "Blank" template from the Starting Points in Swift Playgrounds on your iPad (the same code will work in Xcode).


Once you have your blank template you can copy the code below into Swift Playgrounds and experiment with the data points.

import PlaygroundSupport
import MapKit

let seminyak = CLLocationCoordinate2D(latitude: -8.693793, longitude: 115.162216)

// Now let's create a MKMapView
let mapView = MKMapView(frame: CGRect(x:0, y:0, width:800, height:800))

// Define a region for our map view
var mapRegion = MKCoordinateRegion()

let mapRegionSpan = 1.02 = seminyak
mapRegion.span.latitudeDelta = mapRegionSpan
mapRegion.span.longitudeDelta = mapRegionSpan

mapView.setRegion(mapRegion, animated: true)

mapView.mapType = .hybridFlyover
let camera = MKMapCamera(lookingAtCenter: seminyak, fromDistance: 550000, pitch: 30, heading: 262) = camera

// Create a map annotation
let seminyakAnnotation = MKPointAnnotation() 
seminyakAnnotation.coordinate = seminyak
seminyakAnnotation.title = "Seminyak, Bali"

let lombokAnnotation = MKPointAnnotation()
lombokAnnotation.coordinate = CLLocationCoordinate2D(latitude: -8.287, longitude: 116.452)
lombokAnnotation.title = "Epicenter"
lombokAnnotation.subtitle = "Depth: 25.6km, Magnitude: 6.9"


// Add the created mapView to our Playground Live View
PlaygroundPage.current.liveView = mapView
Create game Sprites with Keynote

Create game Sprites with Keynote

Exploring Art in Virtual Reality

Exploring Art in Virtual Reality