Introducing MapKit JS - Apple

152
#WWDC18 © 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Vicki Murley, MapKit JS Engineering Manager Julien Quint, MapKit JS Engineer Melody Kelly, MapKit JS Engineer Introducing MapKit JS Session 212

Transcript of Introducing MapKit JS - Apple

Page 1: Introducing MapKit JS - Apple

#WWDC18

© 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Vicki Murley, MapKit JS Engineering Manager Julien Quint, MapKit JS Engineer Melody Kelly, MapKit JS Engineer

•Introducing MapKit JS • Session 212

Page 2: Introducing MapKit JS - Apple
Page 3: Introducing MapKit JS - Apple
Page 4: Introducing MapKit JS - Apple
Page 5: Introducing MapKit JS - Apple
Page 6: Introducing MapKit JS - Apple
Page 7: Introducing MapKit JS - Apple
Page 8: Introducing MapKit JS - Apple

MapKit

Page 9: Introducing MapKit JS - Apple

NEW

MapKit JS

Page 10: Introducing MapKit JS - Apple

NEW

BETA

MapKit JS

Page 11: Introducing MapKit JS - Apple

Map initializations a.k.a. map views

250,000

Page 12: Introducing MapKit JS - Apple

Service requests Geocoding, Search, Search autocomplete, and Directions

25,000

Page 13: Introducing MapKit JS - Apple

Per Day

Page 14: Introducing MapKit JS - Apple

Yes, really

Per Day

Page 15: Introducing MapKit JS - Apple

Need more? Contact us. https://developer.apple.com/contact/request/mapkitjs

Page 16: Introducing MapKit JS - Apple

Get a MapKit JS Key https://developer.apple.com/account

Page 17: Introducing MapKit JS - Apple

Get a MapKit JS Key https://developer.apple.com/account

Like, right now

Page 18: Introducing MapKit JS - Apple

Why You'll ❤ MapKit JS

Page 19: Introducing MapKit JS - Apple

Why You'll ❤ MapKit JS

Lets you unify on a single map provider for all platforms

Page 20: Introducing MapKit JS - Apple

Why You'll ❤ MapKit JS

Lets you unify on a single map provider for all platforms

MapKit JS APIs are inspired by native MapKit, and familiar to web developers

Page 21: Introducing MapKit JS - Apple

Why You'll ❤ MapKit JS

Lets you unify on a single map provider for all platforms

MapKit JS APIs are inspired by native MapKit, and familiar to web developers

Provides the native Apple Maps experience in web pages• Localized and accessible• Beautiful cartography• Support for native gestures

Page 22: Introducing MapKit JS - Apple

Why You'll ❤ MapKit JS

Lets you unify on a single map provider for all platforms

MapKit JS APIs are inspired by native MapKit, and familiar to web developers

Provides the native Apple Maps experience in web pages• Localized and accessible• Beautiful cartography• Support for native gestures

Uses adaptive rendering modes

Page 23: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full WebGL map rendering on the client

Page 24: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full WebGL map rendering on the client

Page 25: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full control over map labels for rotation

Page 26: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full control over map labels for rotation

Page 27: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full control over map labels for annotation label collisions

Page 28: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full control over map labels for annotation label collisions

Page 29: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full control over map labels for annotation label collisions

Page 30: Introducing MapKit JS - Apple

Client-Side Rendering (CSR) Full control over map labels for annotation label collisions

Page 31: Introducing MapKit JS - Apple

Web code can run anywhere

Page 32: Introducing MapKit JS - Apple

Not all devices are created equal

Page 33: Introducing MapKit JS - Apple

Labels-Only Client-Side Rendering (LO-CSR) Optimized for low-performance configurations

Page 34: Introducing MapKit JS - Apple

Labels-Only Client-Side Rendering (LO-CSR) Optimized for low-performance configurations

Page 35: Introducing MapKit JS - Apple

Labels-Only Client-Side Rendering (LO-CSR) Optimized for low-performance configurations

Page 36: Introducing MapKit JS - Apple

Server-Side Rendering (SSR) No WebGL? No problem.

Page 37: Introducing MapKit JS - Apple

Server-Side Rendering (SSR) No WebGL? No problem.

Page 38: Introducing MapKit JS - Apple

Adaptive Rendering Modes

Page 39: Introducing MapKit JS - Apple

An ideal mode for every client configuration

Adaptive Rendering Modes

Page 40: Introducing MapKit JS - Apple

An ideal mode for every client configuration

The best mode is automatically chosen

Adaptive Rendering Modes

Page 41: Introducing MapKit JS - Apple

An ideal mode for every client configuration

The best mode is automatically chosen

Most users will get either CSR or LO-CSR

Adaptive Rendering Modes

Page 42: Introducing MapKit JS - Apple

Julien Quint, MapKit JS Engineer

•Using MapKit JS on Your Website

Page 43: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

Page 44: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

•Setting up your map

Page 45: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

•Setting up your map•Navigating and annotating the map

Page 46: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

•Setting up your map•Navigating and annotating the map•Enabling rich interactions with services

Page 47: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

•Setting up your map •Navigating and annotating the map •Enabling rich interactions with services

Page 48: Introducing MapKit JS - Apple

<script src="https://cdn.apple-mapkit.com/mk/5.0.x/mapkit.js"></script>

<div id="map" style="height: 600px; width: 800px;"></div>

<script> // Initialize MapKit JS mapkit.init({ authorizationCallback: done => fetch(…).then(…).then(done); });

let map = new mapkit.Map("map");

</script>

Step 1: Import mapkit.jsSetting Up Your Map

Page 49: Introducing MapKit JS - Apple

<script src="https://cdn.apple-mapkit.com/mk/5.0.x/mapkit.js"></script>

<div id="map" style="height: 600px; width: 800px;"></div>

<script> // Initialize MapKit JS mapkit.init({ authorizationCallback: done => fetch(…).then(…).then(done); });

let map = new mapkit.Map("map");

</script>

Step 1: Import mapkit.jsSetting Up Your Map

Page 50: Introducing MapKit JS - Apple

Setting Up Your Map

<script src="https://cdn.apple-mapkit.com/mk/5.0.x/mapkit.js"></script>

<div id="map" style="height: 600px; width: 800px;"></div>

<script> // Initialize MapKit JS mapkit.init({ authorizationCallback: done => fetch(…).then(…).then(done); });

let map = new mapkit.Map("map");

</script>

Step 2: Create a map container

Page 51: Introducing MapKit JS - Apple

<script src="https://cdn.apple-mapkit.com/mk/5.0.x/mapkit.js"></script>

<div id="map" style="height: 600px; width: 800px;"></div>

<script> // Initialize MapKit JS mapkit.init({ authorizationCallback: done => fetch(…).then(…).then(done); });

let map = new mapkit.Map("map");

</script>

Setting Up Your MapStep 2: Create a map container

Page 52: Introducing MapKit JS - Apple

Setting Up Your Map Step 2: Create a map container

Apple Inc.

Page 53: Introducing MapKit JS - Apple

Setting Up Your Map Step 2: Create a map container

Apple Inc.

Page 54: Introducing MapKit JS - Apple

Setting Up Your Map

<script src="https://cdn.apple-mapkit.com/mk/5.0.x/mapkit.js"></script>

<div id="map" style="height: 600px; width: 800px;"></div>

<script> // Initialize MapKit JS mapkit.init({ authorizationCallback: done => fetch(…).then(…).then(done); });

let map = new mapkit.Map("map");

</script>

Step 3: Initialize MapKit JS

Page 55: Introducing MapKit JS - Apple

<script src="https://cdn.apple-mapkit.com/mk/5.0.x/mapkit.js"></script>

<div id="map" style="height: 600px; width: 800px;"></div>

<script> // Initialize MapKit JS mapkit.init({ authorizationCallback: done => fetch(…).then(…).then(done); });

let map = new mapkit.Map("map");

</script>

Step 4: Create a Map objectSetting Up Your Map

Page 56: Introducing MapKit JS - Apple

Setting Up Your MapApple Inc.

Page 57: Introducing MapKit JS - Apple

Platform and Map Size-Specific Defaults Minimal controls on smaller maps and touch-enabled platforms

Page 58: Introducing MapKit JS - Apple

Platform and Map Size-Specific Defaults Minimal controls on smaller maps and touch-enabled platforms

Page 59: Introducing MapKit JS - Apple

Platform and Map Size-Specific Defaults Minimal controls on smaller maps and touch-enabled platforms

Page 60: Introducing MapKit JS - Apple

Platform and Map Size-Specific Defaults Minimal controls on smaller maps and touch-enabled platforms

Apple logo and Legal text are always present

Page 61: Introducing MapKit JS - Apple

Compass and scale control are adaptive

Configurable Controls for Every Scenario Adaptive controls

Page 62: Introducing MapKit JS - Apple

Compass and scale control are adaptive• On iOS, adaptive compass is shown when rotation

is any non-zero value

Configurable Controls for Every Scenario Adaptive controls

Page 63: Introducing MapKit JS - Apple

Compass and scale control are adaptive• On iOS, adaptive compass is shown when rotation

is any non-zero value• Adaptive scale is shown only while zooming

Configurable Controls for Every Scenario Adaptive controls

Page 64: Introducing MapKit JS - Apple

Compass and scale control are adaptive• On iOS, adaptive compass is shown when rotation

is any non-zero value• Adaptive scale is shown only while zooming

Configurable Controls for Every Scenario Adaptive controls

Page 65: Introducing MapKit JS - Apple

Configurable Controls for Every Scenario Hidden or visible

Remaining controls can be hidden or visible • User location • Zoom • Map type

Page 66: Introducing MapKit JS - Apple

Configurable Controls for Every Scenario Hidden or visible

map.showsUserLocationControl = true; map.showsScale = mapkit.FeatureVisibility.Visible;

Page 67: Introducing MapKit JS - Apple

Configurable Controls for Every Scenario Tinting

map.showsUserLocationControl = true; map.showsScale = mapkit.FeatureVisibility.Visible; map.tintColor = "#ff4040";

Page 68: Introducing MapKit JS - Apple

Configurable Controls for Every Scenario Localization

map.showsUserLocationControl = true; map.showsScale = mapkit.FeatureVisibility.Visible; mapkit.language = "ja-JA";

Page 69: Introducing MapKit JS - Apple

Configurable Controls for Every Scenario Localization

map.showsUserLocationControl = true; map.showsScale = mapkit.FeatureVisibility.Visible; mapkit.language = "iw-IL";

Page 70: Introducing MapKit JS - Apple

Panning (scrolling), zooming, and rotation via gestures can be disabled

To create a static, non-interactive map, set is*Enabled properties to false

Configurable Controls for Every Scenario Disabling interactions

map.isZoomEnabled = false; map.isScrollEnabled = false; map.isRotateEnabled = false;

Page 71: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

•Setting up your map •Navigating and annotating the map •Enabling rich interactions with services

Page 72: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

•Setting up your map •Navigating and annotating the map •Enabling rich interactions with services

Page 73: Introducing MapKit JS - Apple

Navigating and Annotating the Map

Setting the center and region of the map

Marking locations with annotations

Covering areas with overlays

Page 74: Introducing MapKit JS - Apple

Navigating and Annotating the Map

Setting the center and region of the map

Marking locations with annotations

Covering areas with overlays

Page 75: Introducing MapKit JS - Apple

Apple Inc.

Page 76: Introducing MapKit JS - Apple

Moving Around the Map Setting the center of the map

To pan, set the center point of the map to a coordinate

Page 77: Introducing MapKit JS - Apple

Moving Around the Map Setting the region of the map

To also change the scale, set the region of the map to a coordinate region

Page 78: Introducing MapKit JS - Apple

Moving Around the Map Setting center points and regions

The center is a mapkit.Coordinate (i.e., a latitude, longitude pair)

A mapkit.CoordinateRegion is a (center, coordinate span) pair • Center is a mapkit.Coordinate • mapkit.CoordinateSpan is a (latitude delta, longitude delta) pair

Page 79: Introducing MapKit JS - Apple

Moving Around the Map Always displaying the right region

Services return regions that enclose results • Geocoding returns a coordinate and a region • Search returns a boundingRegion that encloses its results

Page 80: Introducing MapKit JS - Apple

Moving Around the Map Always displaying the right region

Services return regions that enclose results • Geocoding returns a coordinate and a region • Search returns a boundingRegion that encloses its results

Use map.showItems(items) to set a region which encloses items

Region changes may be animated

Page 81: Introducing MapKit JS - Apple

Responding to User Interactions

Map objects send event notifications for user interactions • Region change begin and end • Scroll, zoom, rotation begin and end

Following the model of DOM events • map.addEventListener("region-change-end", event => { ... }) • map.removeEventListener("zoom-start", event => { ... })

Page 82: Introducing MapKit JS - Apple

Navigating and Annotating The Map

Setting the center and region of the map

Marking locations with annotations

Covering areas with overlays

Page 83: Introducing MapKit JS - Apple

Annotations 3 Types of annotations

Page 84: Introducing MapKit JS - Apple

Annotations 3 Types of annotations

Marker Annotation

Page 85: Introducing MapKit JS - Apple

Annotations 3 Types of annotations

Image AnnotationMarker Annotation

Page 86: Introducing MapKit JS - Apple

Annotations 3 Types of annotations

Custom DOM Element Annotation

Image AnnotationMarker Annotation

Page 87: Introducing MapKit JS - Apple

Marker Annotations Advanced features, built-in

Page 88: Introducing MapKit JS - Apple

Marker Annotations Advanced features, built-in

Analogous to marker annotations on iOS

Page 89: Introducing MapKit JS - Apple

Marker Annotations Advanced features, built-in

Analogous to marker annotations on iOS

Built-in animation on selection and deselection

Page 90: Introducing MapKit JS - Apple

Marker Annotations Advanced features, built-in

Analogous to marker annotations on iOS

Built-in animation on selection and deselection

Automatically collide out underlying map labels

Page 91: Introducing MapKit JS - Apple

Marker Annotations Advanced features, built-in

Analogous to marker annotations on iOS

Built-in animation on selection and deselection

Automatically collide out underlying map labels

Page 92: Introducing MapKit JS - Apple

Marker Annotations Appearance automatically adapts for the current rendering mode

Client-Side Rendering Mode Title + subtitle display below balloon

Sever-Side Rendering Mode Title + subtitle display in callout

Page 93: Introducing MapKit JS - Apple

Marker Annotations Customize to match your site's look and feel

new mapkit.MarkerAnnotation(coordinate, { title: "Fort de France", subtitle: "Martinique" });

Page 94: Introducing MapKit JS - Apple

Marker Annotations Customize to match your site's look and feel

new mapkit.MarkerAnnotation(coordinate, { title: "Fort de France", subtitle: "Martinique", color: "#53ac79" });

Page 95: Introducing MapKit JS - Apple

Marker Annotations Customize to match your site's look and feel

new mapkit.MarkerAnnotation(coordinate, { title: "Fort de France", subtitle: "Martinique", color: "#53ac79", glyphColor: "#fdc35d" });

Page 96: Introducing MapKit JS - Apple

Marker Annotations Customize to match your site's look and feel

new mapkit.MarkerAnnotation(coordinate, { title: "Fort de France", subtitle: "Martinique", color: "#53ac79", glyphColor: "#fdc35d", glyphImage: { 2: "palm_tree_2x.png" } });

Page 97: Introducing MapKit JS - Apple

Marker Annotations Customize to match your site's look and feel

new mapkit.MarkerAnnotation(coordinate, { title: "Fort de France", subtitle: "Martinique", color: "#53ac79", glyphColor: "#fdc35d", glyphImage: { 2: "palm_tree_2x.png" }, selectedGlyphImage: { 2: "palm_tree_selected_2x.png" } });

Page 98: Introducing MapKit JS - Apple

Marker Annotations Customize to match your site's look and feel

new mapkit.MarkerAnnotation(coordinate, { title: "Fort de France", subtitle: "Martinique", color: "#53ac79", glyphColor: "#fdc35d", glyphImage: { 2: "palm_tree_2x.png" }, selectedGlyphImage: { 2: "palm_tree_selected_2x.png" }, glyphText: "M" });

Page 99: Introducing MapKit JS - Apple

Managing Clutter

Page 100: Introducing MapKit JS - Apple

Annotation Collision with displayPriority

Page 101: Introducing MapKit JS - Apple

Annotation Clustering with clusteringIdentifier

Page 102: Introducing MapKit JS - Apple

Julien Quint, MapKit JS Engineering

•Demo •Using marker annotations

Page 103: Introducing MapKit JS - Apple

Demo Recap

How to create marker annotations from Javascript objects

Set the display priority of annotations to unclutter the map

Style the annotations with a color, and glyph image or a glyph text

Page 104: Introducing MapKit JS - Apple

Image Annotation

Use a raster image for the annotation

Title and subtitle shown in a callout bubble

new mapkit.ImageAnnotation(coordinate, { title: "Madrid", subtitle: "I’ve been there!", url: { 1: "explorer.png", 2: "explorer_2x.png" } });

Page 105: Introducing MapKit JS - Apple

Custom Annotation

Use a DOM element for the annotation

Elements are created on demand

new mapkit.Annotation( coordinate, (coordinate, options) => { let canvas = document.createElement("canvas"); let context = canvas.getContext("2d"); // Draw the pin image and tint it return canvas; }, options );

Page 106: Introducing MapKit JS - Apple

Navigating and Annotating the Map

Setting the center and region of the map

Marking locations with annotations

Covering areas with overlays

Page 107: Introducing MapKit JS - Apple

Overlays

Show distances around a point with a circle overlay

Show a route with a polyline overlay

Show geographical areas with polygon overlays

Page 108: Introducing MapKit JS - Apple

Circle Overlay

let style = new mapkit.Style({ lineWidth: 2, lineDash: [8, 8], strokeColor: "black", fillColor: null, });

new mapkit.CircleOverlay( coordinate, radius, { style } );

Page 109: Introducing MapKit JS - Apple

Polyline Overlay

let style = new mapkit.Style({ strokeOpacity: 0.5, lineWidth: 6 });

new mapkit.PolylineOverlay( points, { style } );

Page 110: Introducing MapKit JS - Apple

Polygon Overlay

let data = { name: "Texas", population: 20851820 };

new mapkit.PolygonOverlay( points, { style, data } );

Page 111: Introducing MapKit JS - Apple

GeoJSON Import

Import data from GeoJSON

Create annotations and overlays from GeoJSON geometry

Customize annotations and overlays through delegate methods

Page 112: Introducing MapKit JS - Apple

Responding to User Interactions

Map, annotation and overlay objects send event notifications for user interactions • Selection and deselection of annotations and overlays • Dragging of annotations

Following the model of DOM events • map.addEventListener("select", event => { ... }) • annotation.removeEventListener("dragging", event => { ... })

Page 113: Introducing MapKit JS - Apple

Using MapKit JS on Your Website Agenda

•Setting up your map •Navigating and annotating the map •Enabling rich interactions with services

Page 114: Introducing MapKit JS - Apple

Melody Kelly, MapKit JS Engineer

•Enabling Rich Interactions •with Services

Page 115: Introducing MapKit JS - Apple

Enabling Rich Interactions with Services

MapKit JS provides interfaces to Apple Maps services • Geocoding • Search and Search autocomplete • Directions

Page 116: Introducing MapKit JS - Apple

Using Apple Maps Services in MapKit JS

Using any service requires the same four steps:

1. Create an instance of service object

2. Specify request parameters and options

3. Make a request

4. Handle the response • Response is returned asynchronously via a callback function

Page 117: Introducing MapKit JS - Apple

Geocoding

let geocoder = new mapkit.Geocoder(); geocoder.lookup("McEnery Convention Center", (error, data) => { if (error) { return; } map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate)); });

geocoder.reverseLookup(new mapkit.Coordinate(37.3298857, -121.8888872), (error, data) => { … });

Page 118: Introducing MapKit JS - Apple

Geocoding

let geocoder = new mapkit.Geocoder(); geocoder.lookup("McEnery Convention Center", (error, data) => { if (error) { return; } map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate)); });

geocoder.reverseLookup(new mapkit.Coordinate(37.3298857, -121.8888872), (error, data) => { … });

Page 119: Introducing MapKit JS - Apple

Geocoding

let geocoder = new mapkit.Geocoder({ getsUserLocation: true }); geocoder.lookup("McEnery Convention Center", (error, data) => { if (error) { return; } map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate)); });

geocoder.reverseLookup(new mapkit.Coordinate(37.3298857, -121.8888872), (error, data) => { … });

Page 120: Introducing MapKit JS - Apple

Geocoding

let geocoder = new mapkit.Geocoder({ getsUserLocation: true }); geocoder.lookup("McEnery Convention Center", (error, data) => { if (error) { return; } map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate)); });

geocoder.reverseLookup(new mapkit.Coordinate(37.3298857, -121.8888872), (error, data) => { … });

Page 121: Introducing MapKit JS - Apple

Geocoding

let geocoder = new mapkit.Geocoder({ getsUserLocation: true }); geocoder.lookup("McEnery Convention Center", (error, data) => { if (error) { return; } map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate)); });

geocoder.reverseLookup(new mapkit.Coordinate(37.3298857, -121.8888872), (error, data) => { … });

Page 122: Introducing MapKit JS - Apple

Geocoding

let geocoder = new mapkit.Geocoder({ getsUserLocation: true }); geocoder.lookup("McEnery Convention Center", (error, data) => { if (error) { return; } map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate)); });

geocoder.reverseLookup(new mapkit.Coordinate(37.3298857, -121.8888872), (error, data) => { … });

Page 123: Introducing MapKit JS - Apple

Geocoding

let geocoder = new mapkit.Geocoder({ getsUserLocation: true }); geocoder.lookup("McEnery Convention Center", (error, data) => { if (error) { return; } map.addAnnotation(new mapkit.MarkerAnnotation(data.results[0].coordinate)); });

geocoder.reverseLookup(new mapkit.Coordinate(37.3298857, -121.8888872), (error, data) => { … });

Page 124: Introducing MapKit JS - Apple

Service Context

Provide context to search or geocoder by setting properties in the constructor or request • getsUserLocation • coordinate • region

Page 125: Introducing MapKit JS - Apple

Search

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Page 126: Introducing MapKit JS - Apple

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Search

Page 127: Introducing MapKit JS - Apple

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Search

Page 128: Introducing MapKit JS - Apple

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Search

Page 129: Introducing MapKit JS - Apple

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Search

Page 130: Introducing MapKit JS - Apple

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Search

Page 131: Introducing MapKit JS - Apple

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Search

Page 132: Introducing MapKit JS - Apple

Search

let search = new mapkit.Search({ getsUserLocation: true }); search.search("coffee", (error, data) => { if (error) { // handle search error return; } let annotations = data.places.map(place => { let annotation = new mapkit.MarkerAnnotation(place.coordinate); annotation.title = place.name; return annotation; }); map.showItems(annotations); });

Page 133: Introducing MapKit JS - Apple

Search AutoComplete

Search.autocomplete("san", (error, data) => { if (error) { // handle search autocomplete error return; } // handle data });

Page 134: Introducing MapKit JS - Apple

Search AutoComplete

Search.autocomplete("san", (error, data) => { if (error) { // handle search autocomplete error return; } // handle data });

Page 135: Introducing MapKit JS - Apple

Directions

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose" }, (error, data) => { // display route steps and path });

Page 136: Introducing MapKit JS - Apple

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose" }, (error, data) => { // display route steps and path });

Directions

Page 137: Introducing MapKit JS - Apple

let directions = new mapkit.Directions( { language: "fi-FI" }); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose" }, (error, data) => { // display route steps and path });

Directions

Page 138: Introducing MapKit JS - Apple

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose" }, (error, data) => { // display route steps and path });

Directions

Page 139: Introducing MapKit JS - Apple

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose" }, (error, data) => { // display route steps and path });

Directions

Page 140: Introducing MapKit JS - Apple

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose”, transportType: Directions.Transport.Walking }, (error, data) => { // display route steps and path });

Directions

Page 141: Introducing MapKit JS - Apple

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose”, requestsAlternateRoutes: true }, (error, data) => { // display route steps and path });

Directions

Page 142: Introducing MapKit JS - Apple

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose”, requestsAlternateRoutes: true }, (error, data) => { // display route steps and path });

Directions

Page 143: Introducing MapKit JS - Apple

Directions

let directions = new mapkit.Directions(); directions.route({ origin: "747 Howard St, San Francisco", destination: "150 W San Carlos St, San Jose”, requestsAlternateRoutes: true }, (error, data) => { // display route steps and path });

Page 144: Introducing MapKit JS - Apple

Julien Quint, MapKit JS Engineering

•Demo •Directions and user interactions

Page 145: Introducing MapKit JS - Apple

Demo Recap

How to react to user events

Get driving directions from the MapKit JS service

Draw polyline overlays

Implement selection behavior for overlays

Page 146: Introducing MapKit JS - Apple

Key Takeaways

Page 147: Introducing MapKit JS - Apple

Key Takeaways

MapKit JS delivers a top-notch map experience on the web

Page 148: Introducing MapKit JS - Apple

Key Takeaways

MapKit JS delivers a top-notch map experience on the web

Unify on a single map provider with familiar, flexible APIs

Page 149: Introducing MapKit JS - Apple

Key Takeaways

MapKit JS delivers a top-notch map experience on the web

Unify on a single map provider with familiar, flexible APIs

Get a MapKit JS key at developer.apple.com and try it out today!

Page 150: Introducing MapKit JS - Apple

https://developer.apple.com/maps/mapkitjs

Page 151: Introducing MapKit JS - Apple

More Informationhttps://developer.apple.com/wwdc18/212

Getting and Using a MapKit JS Key WWDC 2018 Video

Mapping and Location Technologies Lab Technology Lab 3 Wednesday 9:00AM

Mapping and Location Technologies Lab Technology Lab 4 Friday 9:00AM

Page 152: Introducing MapKit JS - Apple