20
Google Maps API Brief introduction Maksim Golivkin www.androidaalto.org www.mobileguild.eu Twitter: MaksimGolivkin 13.11.2010 Android Aalto Community

Google Maps API for Android

Embed Size (px)

DESCRIPTION

Presenting use of Maps, distance calculation, geolocation. Code examples.

Citation preview

Page 1: Google Maps API for Android

Google Maps APIBrief introduction

Maksim Golivkin

www.androidaalto.orgwww.mobileguild.eu

Twitter: MaksimGolivkin

13.11.2010 Android Aalto Community

Page 2: Google Maps API for Android

Plan

13.11.2010 Android Aalto Community

Intro to Google Maps API MapView & MapActivityOverlaysDistancesBalloons

GeocodingUI update with handlers

Page 3: Google Maps API for Android

Intro to maps API: New Project

13.11.2010 Android Aalto Community

Target build and emulator have to use Google API for platform you have chosen. For instance, Google API for 1.6

Page 4: Google Maps API for Android

Intro to maps API : AndroidManifest.xml

13.11.2010 Android Aalto Community

Things to remember: uses-library declaration for runtime;permissions to access Internet and location services.

Page 5: Google Maps API for Android

MapView: Layout

13.11.2010 Android Aalto Community

If inappropriate API key is used, map isn't displayed.

For one Google account one can generate several keys. How to generate your own:http://code.google.com/android/add-ons/google-apis/mapkey.html

Page 6: Google Maps API for Android

MapActivity onCreate

13.11.2010 Android Aalto Community

Page 7: Google Maps API for Android

Overlays

13.11.2010 Android Aalto Community

Each overlay is information layer on the map. Google Maps has 3 overlay classes (main purpose below):

Overlay - drawing complex figures on the map and capturing touch moves.

ItemizedOverlay - abstract, extends Overlay, for drawing of multiple markers.

MyLocationOverlay - to display user location on the map.

Page 8: Google Maps API for Android

Overlays: hierarchy

13.11.2010 Android Aalto Community

Page 9: Google Maps API for Android

Overlays: ItemizedOverlay #1

13.11.2010 Android Aalto Community

Most important thing:

on every content change call protected populate method;

include populate call in constructor Reference: http://code.google.com/p/android/issues/detail?id=2035

Page 10: Google Maps API for Android

Overlays: ItemizedOverlay #2

13.11.2010 Android Aalto Community

Page 11: Google Maps API for Android

Overlays: ItemizedOverlay usage

13.11.2010 Android Aalto Community

Page 12: Google Maps API for Android

Overlays: MyLocationOverlay

13.11.2010 Android Aalto Community

Convenient to display user location on map. Most important thing: call disableMyLocation and disableCompass (if enabled), when activity goes to background.

Page 13: Google Maps API for Android

Overlays: MyLocationOverlay usage

13.11.2010 Android Aalto Community

Page 14: Google Maps API for Android

Distance

13.11.2010 Android Aalto Community

Note:Google Maps API uses (int) micro-degrees for coordinates;

Android Location package uses (double) degrees for coordinates;

microdegrees = degrees * 1000 000; ormicrodegrees = degress * 1E6;

degrees = microdegrees / (double)1E6;

Page 15: Google Maps API for Android

Distance calculation

13.11.2010 Android Aalto Community

Page 16: Google Maps API for Android

Balloons : usage

13.11.2010 Android Aalto Community

Page 17: Google Maps API for Android

Balloons

13.11.2010 Android Aalto Community

Nice small existing library. Available at:https://github.com/jgilfelt/android-mapviewballoons

Page 18: Google Maps API for Android

Geocoding

13.11.2010 Android Aalto Community

Geocoding - translating coordinates to address.Reverse geocoding - translating address from coordinates.

GeoCoder class.

Do geocoding in background thread!

Page 19: Google Maps API for Android

UI update with Handler

13.11.2010 Android Aalto Community

Nested anonymous classes are ugly!

Alternative: Handler + Message + Bundle.

Note: when updating UI, be sure to instantiate Handler (or Handler child class) in UI thread. For example, in onCreate method.

Page 20: Google Maps API for Android

Thank you!

13.11.2010 Android Aalto Community

Example code can be found at:http://mobileguild.eu/code/FindHackatron.zip