0% found this document useful (0 votes)
65 views20 pages

Google Maps API: Brief Introduction

This document provides an overview of the Google Maps API for Android, including how to set up a basic map view, add overlays, calculate distances, and perform geocoding. It discusses key classes like MapView, MapActivity, Overlay, ItemizedOverlay and MyLocationOverlay. It also recommends using handlers to update the UI and provides links to example code and a library for map balloons.

Uploaded by

Còi Anh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views20 pages

Google Maps API: Brief Introduction

This document provides an overview of the Google Maps API for Android, including how to set up a basic map view, add overlays, calculate distances, and perform geocoding. It discusses key classes like MapView, MapActivity, Overlay, ItemizedOverlay and MyLocationOverlay. It also recommends using handlers to update the UI and provides links to example code and a library for map balloons.

Uploaded by

Còi Anh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Google Maps API

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

Plan
Intro to Google Maps API MapView & MapActivity Overlays Distances Balloons Geocoding UI update with handlers

13.11.2010

Android Aalto Community

Intro to maps API: New Project


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

13.11.2010

Android Aalto Community

Intro to maps API : AndroidManifest.xml

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

13.11.2010

Android Aalto Community

MapView: Layout

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

13.11.2010

Android Aalto Community

MapActivity onCreate

13.11.2010

Android Aalto Community

Overlays
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.

13.11.2010

Android Aalto Community

Overlays: hierarchy

13.11.2010

Android Aalto Community

Overlays: ItemizedOverlay #1

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

13.11.2010

Android Aalto Community

Overlays: ItemizedOverlay #2

13.11.2010

Android Aalto Community

Overlays: ItemizedOverlay usage

13.11.2010

Android Aalto Community

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

13.11.2010

Android Aalto Community

Overlays: MyLocationOverlay usage

13.11.2010

Android Aalto Community

Distance
Note: Google Maps API uses (int) micro-degrees for coordinates; Android Location package uses (double) degrees for coordinates;

microdegrees = degrees * 1000 000; or microdegrees = degress * 1E6; degrees = microdegrees / (double)1E6;

13.11.2010

Android Aalto Community

Distance calculation

13.11.2010

Android Aalto Community

Balloons : usage

13.11.2010

Android Aalto Community

Balloons
Nice small existing library. Available at:
https://github.com/jgilfelt/androidmapviewballoons

13.11.2010

Android Aalto Community

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

GeoCoder class.

Do geocoding in background thread!

13.11.2010

Android Aalto Community

UI update with Handler


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.

13.11.2010

Android Aalto Community

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

Thank you!

13.11.2010

Android Aalto Community

You might also like