Infinum Android Talks #02 - Android Maps Extensions
Click here to load reader
-
Upload
infinum-ltd -
Category
Technology
-
view
222 -
download
0
description
Transcript of Infinum Android Talks #02 - Android Maps Extensions
Android Maps Extensions
Ana Baotić
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
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" />
Adding a map#layout
Adding a map#activity
Adding a marker
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)
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
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()
Basic implementation
● Extend SupportMapFragment● call getExtendedMap instead of getMap on
SupportMapFragment (or MapView)
Code example
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
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
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/
Thank you!