Maps V2... And You!


Published on

from the AnDevCon Boston 2013 conference

Published in: Technology, Business
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Maps V2... And You!

  1. 1. Copyright © 2013 CommonsWare, LLCMapsV2...AndYou!AnDevCon Boston 2013
  2. 2. Copyright © 2013 CommonsWare, LLCMaps: Not Invented in 2008!● Android 1.0: Maps SDK Add-On– Same as what Google Maps app used– Creaky API, particularly with fragments● The Fork– Google Maps started using own engine– Gained more features than old SDK add-onsupported
  3. 3. Copyright © 2013 CommonsWare, LLCMaps: Not Invented In 2012 Either!● MapsV2– Introduced in late 2012– New API, new device requirements, new features● Close to full Google Maps app● MapsV1: Deprecated!– Can no longer official get MapsV1 API keys– Still runs, if you have keys from before
  4. 4. Copyright © 2013 CommonsWare, LLCLegal, Without Ease● MapsV1 and MapsV2:Terms of Service– Required to use these APIs– Put restrictions on how you use those APIs● Example: no real-time turn-by-turn navigation– IANALNDIPOOTV● Please have qualified legal counsel review theseterms if they concern you
  5. 5. Copyright © 2013 CommonsWare, LLCUsers Have Issues (No, Really!)● Requirements– Play Services Framework● May already exist● May be available from the Play Store● Not available by other legitimate means– OpenGL ES 2.0● On 99.8% of devices with the Play Store
  6. 6. Copyright © 2013 CommonsWare, LLCYou Have IssuesToo● No Emulator Support– Play Services Framework not available inemulator images● Google has indicated this will be resolved...sometime– Various workarounds of dubious legalitydocumented on teh Interwebs● Expectation:Test on Hardware
  7. 7. Copyright © 2013 CommonsWare, LLCPreparation M● Setting Up MapsV2 Development– Download Google Play Services SDK from SDKManager (in Extras area)– Result: Android Library Project● Eclipse: import into workspace, then attach toapplication project● Command-line: android update project● Other IDEs: ???
  8. 8. Copyright © 2013 CommonsWare, LLCYet More Preparation M● MapsV2 API Key– No, its not the same as your MapsV1 API key– Obtain it from the Google API Console– Tied to your package name, signing key● SHA-1 fingerprint vs. MD5● Up to ~5 signing key/package name pairs per API key
  9. 9. Copyright © 2013 CommonsWare, LLCLets Get Mappy, People● A MapsV2 Project– ...does not need to use a Google APIs SDK as abuild target– …does need to restrict to OpenGL ES 2.0 devices● Or make optional, but test at runtime– ...does need permissions, including a custom one– ...does need a MapsV2 API key
  10. 10. Copyright © 2013 CommonsWare, LLCLets Get Mappy, People● A MapsV2 Activity– ...does not have to inherit from any magicactivity class– ...does need to use MapFragment,SupportMapFragment, or MapView– ...does have a lot of legwork to ensure MapsV2 isavailable, the user has access to license terms,etc.● ...all of which can be nicely abstracted away
  11. 11. Copyright © 2013 CommonsWare, LLCWorking (with a map) For a Living● GoogleMap– Your gateway to the actual mapping API– Obtained from MapFragment,SupportMapFragment, or MapView viagetMap()– Most method calls result in IPC● Comparatively slow● Avoid doing lots of these in a tight loop● Must be called on the main application thread
  12. 12. Copyright © 2013 CommonsWare, LLCShowing Something Useful● CameraUpdate– Changes in characteristics of the “camera”● Center, zoom, etc.– Create using CameraUpdateFactory– Apply to GoogleMap● moveCamera()● animateCamera()
  13. 13. Copyright © 2013 CommonsWare, LLCTyping Up a Map● Default MapType: MAP_TYPE_NORMAL● Changing MapTypes– Choose a type (e.g., MAP_TYPE_HYBRID)– Call setMapType() on your GoogleMap
  14. 14. Copyright © 2013 CommonsWare, LLCMarking Up a Map● No More Overlays!● Add MarkersVia addMarker()– Takes a MarkerOptions object– Fluent API to describe marker– Position as a LatLng● No more microdegrees!– Provide title and snippet for default pop-up“info window”
  15. 15. Copyright © 2013 CommonsWare, LLCBYO Info● Controlling the InfoWindows– Implement InfoWindowAdapter interface● getInfoContents(): your ownView to pour intoMapsV2-supplied frame● getInfoWindow(): your ownView with your ownframe– Associate with GoogleMap viasetInfoWindowAdapter()
  16. 16. Copyright © 2013 CommonsWare, LLCTaps, Sans Bugle● MarkerTaps– Implement OnMarkerClickListener interface● onMarkerClick() called when user taps on aMarker– Associate with GoogleMap viasetOnMarkerClickListener()
  17. 17. Copyright © 2013 CommonsWare, LLCMarkers Can Be a Real Drag● Marker Drag-and-Drop– Call draggable(true) on MarkerOptions– Implement OnMarkerDragListener interface● onMarkerDragStart()● onMarkerDrag()● onMarkerDragEnd()– Associate with GoogleMap viasetOnMarkerDragListener()
  18. 18. Copyright © 2013 CommonsWare, LLCWhereYou At?● Enabling “My Location”– setMyLocationEnabled(true) onGoogleMap● Adds “My Location” button● Requires suitable permissions (e.g.,ACCESS_FINE_LOCATION)● When tapped, camera follows the user– OnMyLocationChangeListener andsetOnMyLocationChangeListener()
  19. 19. Copyright © 2013 CommonsWare, LLCPages of Maps● MapFragment andViewPager– It just works!● Problem:ViewPagerWants Gestures– Default: cannot pan map horizontally– Solution: CustomViewPager subclass, overridingcanScroll(), to indicate widgets that handletheir own scrolling
  20. 20. Copyright © 2013 CommonsWare, LLCDirty Details, Done Dirt Cheap● AbstractMapActivity Features– Determining if Play Services Framework isavailable– Leading user to install Play Services Frameworkif possible– Showing license terms
  21. 21. Copyright © 2013 CommonsWare, LLCOther Fun Stuff● Supplying own location data● Polylines, polygons, and circles● Controlling default gestures● TileOverlay and GroundOverlay– Images displayed on top of map tiles● ...and more!
  22. 22. Copyright © 2013 CommonsWare, LLCDo Worry, Be Mappy● Problems and Issues– Reported leaks in configuration changes– GLSurfaceView, animations, and black bars– Play Services Framework detection buggy– IPC and performance– OpenGL ES 2.0 requirement
  23. 23. Copyright © 2013 CommonsWare, LLCSpeaker ContactInformationSource Code