Developers Google Maps Android API v2 Make your Android app pop - - PowerPoint PPT Presentation

developers google maps android api v2
SMART_READER_LITE
LIVE PREVIEW

Developers Google Maps Android API v2 Make your Android app pop - - PowerPoint PPT Presentation

Developers Google Maps Android API v2 Make your Android app pop with Google Maps Android API v2 Anthony Morris Jan-Felix Schmakeit Tech Lead, Android Maps API Android Developer Relations Code, Slides, Worksheet: http://goo.gl/MfY67 Welcome!


slide-1
SLIDE 1

Developers

slide-2
SLIDE 2

Google Maps Android API v2

Make your Android app pop with Google Maps Android API v2

Anthony Morris Tech Lead, Android Maps API Jan-Felix Schmakeit Android Developer Relations

Code, Slides, Worksheet: http://goo.gl/MfY67

slide-3
SLIDE 3

Welcome!

http://goo.gl/MfY67

slide-4
SLIDE 4

Let's take a walking tour of London

Our App for today: Tour of London

slide-5
SLIDE 5

http://goo.gl/MfY67

slide-6
SLIDE 6

http://goo.gl/MfY67

slide-7
SLIDE 7

Codelab Format

6 Lessons: Add a map to an app Help each other! Ask our friendly Teaching Assistants Bonus challenges: ... and super bonus challenges: Worksheet, Code, Slides: http://goo.gl/MfY67

slide-8
SLIDE 8

Our Agenda

  • 0. Get set up
  • 1. Map
  • 2. Markers
  • 3. Info windows
  • 4. Layers
  • 5. Camera
  • 6. Shapes

http://goo.gl/MfY67

slide-9
SLIDE 9

Prerequisites

http://goo.gl/MfY67

slide-10
SLIDE 10

See worksheet! IDE for Android Development

○ Eclipse or Android Studio ○ If unsure, get the Android SDK Bundle: http://developer.android.com/sdk

Android SDK, API 17

○ Google Play services library included in codelab archive

Required Downloads

http://goo.gl/MfY67

slide-11
SLIDE 11

Android Device

Required: Tablet and/or phone with Android 4.0 or above Unfortunately you can't use the emulator

http://goo.gl/MfY67

slide-12
SLIDE 12

Google Play services

Google Maps, Google+, Location, Games and more! On all Google Play devices, Froyo+

http://goo.gl/MfY67

slide-13
SLIDE 13

Lesson 0: Get set up

Importing the project, run the app on your device

slide-14
SLIDE 14

Worksheet: Lesson 0 http://goo.gl/MfY67 What you will do:

  • Setup IDE and environment
  • Import skeleton project
  • Compile and deploy to device

Lesson 0: Get set up

slide-15
SLIDE 15

Lesson 1: Add Map

MapFragment, API Key, Permissions

slide-16
SLIDE 16

API Key - Android Maps API v2

You will need an API key

  • Unlimited usage
  • Register with your keystore + package name
slide-17
SLIDE 17

MapFragment

It's a Fragment... with a map!

  • com.google.android.gms.maps.MapFragment
  • Use GoogleMap object to interact with map:

getMap() What about Gingerbread?

  • Use SupportMapFragment!
slide-18
SLIDE 18

Android Manifest

Specify API key Require OpenGL ES 2 Required Permissions:

  • Custom Maps Permission
  • Internet Access
  • Write External Storage Permission
  • Optional: Coarse or Fine Location
slide-19
SLIDE 19

Worksheet: Lesson 1 http://goo.gl/MfY67 What you will do:

  • AndroidManifest.xml
  • Extend MapFragment
  • Basic setup

Lesson 1: Add a Map

slide-20
SLIDE 20

Lesson 2: Markers

Markers, custom icons, keeping track of them

slide-21
SLIDE 21

Indicates a point on a map Properties:

  • Position (required)
  • Title and snippet
  • Dragging
  • Visibility
  • Icon (default icon, coloured icon, custom icon)

and anchor

What's a Marker?

slide-22
SLIDE 22

Adding a Marker

Java

map.addMarker(new MarkerOptions() .position(new LatLng(51.5075744, -0.0992315));

slide-23
SLIDE 23

Worksheet: Lesson 2 http://goo.gl/MfY67 What you will do:

  • Add markers
  • Set custom icons

Lesson 2: Markers

slide-24
SLIDE 24

Lesson 3: Info Windows

Custom Info Windows, click events

slide-25
SLIDE 25

What's an info window?

Default Custom Content Custom Window

slide-26
SLIDE 26

InfoWindowAdapter: custom content

Java

class CustomInfoWindowAdapter implements InfoWindowAdapter { View getInfoWindow(Marker marker) { // No custom info window return null; } View getInfoContents(Marker marker) { View fancyContents; // ... return fancyContents; } }

slide-27
SLIDE 27

A few notes about info windows

Only a snapshot!

  • Need to call showInfoWindow() to refresh
  • Can't use live views

OnInfoWindowClickListener

  • Only single target
slide-28
SLIDE 28

Worksheet: Lesson 3 http://goo.gl/MfY67 What you will do:

  • Add custom info window
  • Add info window click event

Lesson 3: Info Windows

slide-29
SLIDE 29

Lesson 4: Layers

Map Types, Traffic, My Location

slide-30
SLIDE 30

Map Types

Normal Hybrid Satellite Terrain

slide-31
SLIDE 31

Set Map Type

Java

GoogleMap map; map.setMapType(GoogleMap.MAP_TYPE_HYBRID);

slide-32
SLIDE 32

My Location & Traffic

Java

GoogleMap map; map.setMyLocationEnabled(true); map.setTrafficEnabled(true);

slide-33
SLIDE 33

Worksheet: Lesson 4 http://goo.gl/MfY67 What you will do:

  • Change base map type
  • Enable My Location layer

Lesson 4: Layers

slide-34
SLIDE 34

Lesson 5: Camera Movement

CameraPositions, CameraUpdates, animateCamera

slide-35
SLIDE 35

Changing the camera

First: Need a CameraUpdate from CameraUpdateFactory There's also: newLatLngZoom, newCameraPositon, newLatLngBounds, zoomIn/Out, scroll, ... Then: animate (or move) the camera

CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(new LatLng(-33.89, 151.27)); mMap.animateCamera(cameraUpdate);

slide-36
SLIDE 36

Worksheet: Lesson 5 http://goo.gl/MfY67 What you will do:

  • Animate to POIs
  • Reset camera position

Lesson 5: Camera Movement

slide-37
SLIDE 37

Lesson 6: Shapes

PolylineOptions

slide-38
SLIDE 38

Polyline Polygon Circle

Add shapes to your map

slide-39
SLIDE 39

Polyline Polygon Circle

Add shapes to your map

slide-40
SLIDE 40

Add a polyline

Java

PolylineOptions options = new PolylineOptions() .add(new LatLng(a,b)) .add(new LatLng(c,d)) .color(0xFFAA0000) .width(10); // Add it to the map. mMap.addPolyline(options);

slide-41
SLIDE 41

Changing Properties

Common shape properties:

  • width
  • stroke color
  • z-index
  • visibility

Filled shapes (polygons, circles):

  • fill color

Lines:

  • geodesic segments
slide-42
SLIDE 42

Worksheet: Lesson 6 http://goo.gl/MfY67 What you will do:

  • Add route line

Lesson 6: Shapes

slide-43
SLIDE 43

Final Tour of London

What you have built today

slide-44
SLIDE 44
slide-45
SLIDE 45

Our App

API features:

  • MapFragment
  • Markers
  • Info windows
  • Layers
  • Camera
  • Shapes

... and there's more: https://developers.google.com/maps/documentation/android/

slide-46
SLIDE 46

Thank you!

Link to codelab (notes, presentation, code): http://goo.gl/MfY67

Anthony Morris Jan-Felix Schmakeit

slide-47
SLIDE 47

Extra Material

slide-48
SLIDE 48

Default marker with custom colour

Java

map.addMarker(new MarkerOptions() .position(new LatLng(51.51309, -0.12441)) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))

slide-49
SLIDE 49

Custom marker icon

Java

map.addMarker(new MarkerOptions() .position(new LatLng(51.5075744, -0.0992315)) .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_museum));