Infinum Android Talks #02 - Android Maps Extensions

15

Click here to load reader

description

With the highly anticipated v2 update of Google Maps for Android we made a big leap forward, with just a couple of steps back. We will show you what has changed, what new problems arose and how Android Maps Extensions helped us solve them.

Transcript of Infinum Android Talks #02 - Android Maps Extensions

Page 1: Infinum Android Talks #02 - Android Maps Extensions

Android Maps Extensions

Ana Baotić

Page 2: Infinum Android Talks #02 - Android Maps Extensions

Android Maps v2

Android Maps v2 (end of 2012.)● no more extending MapActivity

● simpler way to add markers (no more extending ItemizedOverlay)

● fine tuning: position, anchor, color, icon, snippet, title, etc

https://developers.google.com/maps/documentation/android/marker#add_a_marker

Page 3: Infinum Android Talks #02 - Android Maps Extensions

Adding a map#AndroidManifest● <meta-data

android:name="com.google.android.maps.v2.API_KEY"

android:value="API_KEY"/>

● <uses-permission android:name="android.permission.INTERNET"/>

● <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

● <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

● <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

● <uses-feature

android:glEsVersion="0x00020000"

android:required="false"/>

● <uses-library android:name="com.google.android.maps" />

Page 4: Infinum Android Talks #02 - Android Maps Extensions

Adding a map#layout

Page 5: Infinum Android Talks #02 - Android Maps Extensions

Adding a map#activity

Page 6: Infinum Android Talks #02 - Android Maps Extensions

Adding a marker

Page 7: Infinum Android Talks #02 - Android Maps Extensions

App requirements

● Add a marker for each poi● Show different icon (selected) in marker's onClick event (change icon)● Display full poi information (get poi object for selected marker) ● Remove marker from map (get marker from the map for a specific poi)

Page 8: Infinum Android Talks #02 - Android Maps Extensions

Problems

● Cannot change properties of an existing marker– remove the marker and add a new one

– until Google play services rev.7

● Marker has no knowledge of its poi– store KV pairs in an arbitrary structure

– getId() method (unreilable), setId(Object value) non existent

– cannot get a marker on the map by an id

● Cannot extend the Marker class– public final class Marker

Page 9: Infinum Android Talks #02 - Android Maps Extensions

Android Maps Extensions lib

● http://androidmapsextensions.com/● Object getData() and setData(Object) on Marker, Circle, GroundOverlay, Polygon, Polyline, etc.

● List<Marker> GoogleMap.getDisplayedMarkers()

● List<Marker> GoogleMap.getMarkers()

● List<Circle> GoogleMap.getCircles()

● List<GroundOverlay> GoogleMap.getGroundOverlays()

● boolean Circle.contains(LatLng)

● Marker GoogleMap.getMarkerShowingInfoWindow()

Page 10: Infinum Android Talks #02 - Android Maps Extensions

Basic implementation

● Extend SupportMapFragment● call getExtendedMap instead of getMap on

SupportMapFragment (or MapView)

Page 11: Infinum Android Talks #02 - Android Maps Extensions

Code example

Page 12: Infinum Android Talks #02 - Android Maps Extensions

Prerequisites

● Maven Central repo (added three weeks ago)

– dependencies {– compile 'com.google.android.gms:play-services:4.0.30'

– compile 'com.androidmapsextensions:android-maps-extensions:2.0+'

}

● External library for Eclipse projects

Page 13: Infinum Android Talks #02 - Android Maps Extensions

Google Maps Android API Utility Library

● Enables advaced features

– Customization of markers via bubble icons

– Markers are more like info windows

– Markers can be styled

– Cluster manager

– PolyUtil for converting polylines and polygons to latlng

– Enabled interoperability with Google Maps API web services

– SphericalUtil for computation of distances, areas and headings base on latitudes and longitudes

Page 14: Infinum Android Talks #02 - Android Maps Extensions

Links● Intro to Android Google Maps

– https://developers.google.com/maps/documentation/android/intro

● Old maps reference

– https://developers.google.com/maps/documentation/android/v1/hello-mapview?hl=en

● Android maps extenstions

– https://code.google.com/p/android-maps-extensions/

● Android maps utils library

– http://googlemaps.github.io/android-maps-utils/