Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learnings from using the Google Maps API V2 for Android

Learnings from using the Google Maps API V2 for Android

Slides of my presentation at the Android Developer Days in Ankara 2013.

D2a06312762581d504ba0a25e5a90def?s=128

Benjamin Weiss

June 15, 2013
Tweet

More Decks by Benjamin Weiss

Other Decks in Technology

Transcript

  1. from using the Google Maps API V2 for Android Learnings

  2. Benjamin Weiss http://gplus.to/keyboardsurfer Twitter: @keyboardsurfer Senior Software Developer at ImmobilienScout24

    Organizer: GDG Android in Berlin Co-Organizer of many Android events
  3. Agenda • A look back • Old VS New •

    Getting started with Maps V2 • Caveats and Pitfalls
  4. You've come a long way

  5. Comparison

  6. Tiles Vector graphics Load paths and render them locally Bitmaps

    Load whole bitmaps and display them locally
  7. Fragmentation MapFragment • Display multiple maps • Embeddable MapView •

    One Map at a time • Map VS other content
  8. UI Enhancement Direct interaction 1. Create Markers 2. Add them

    to the Map Overlay 1. Create an Overlay 2. Add it to the Map 3. Create Markers 4. Add to Overlay
  9. Getting started

  10. Getting started https://code.google.com/apis/console

  11. Getting started Obtain API keys keytool -list -v -keystore $name

    -alias $name SHA1: f0:00:... keystoreSHA1 + ';' + packageName
  12. Add info to your AndroidManifest.xml <permission android:name="myapp.package.permission. MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission

    android:name="myapp.package.permission. MAPS_RECEIVE"/> Getting started
  13. Add info to your AndroidManifest.xml <permission android:name="myapp.package.permission. MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission

    android:name="myapp.package.permission. MAPS_RECEIVE"/> Getting started
  14. Getting started https://developers.google.com/ maps/documentation/android/start

  15. Pitfalls

  16. I can haz maps?

  17. I can haz maps? GooglePlayServicesUtil. isGooglePlayServicesAvailable(activity);

  18. You can haz maps ConnectionResult.SUCCESS

  19. What have you done? ConnectionResult. DEVELOPER_ERROR

  20. Not yet can haz ConnectionResult. RESOLUTION_REQUIRED

  21. Not yet can haz ConnectionResult. startResolutionForResult(...)

  22. No can haz! ConnectionResult. SERVICE_MISSING

  23. No can haz! ConnectionResult. SERVICE_DISABLED

  24. No can haz! ConnectionResult. getErrorDialog(...)

  25. State management java.lang.IllegalStateException: Uninitialized at maps.m.y.c(Unknown Source) at maps.z.a.b(Unknown Source)

    at maps.z.b.m(Unknown Source) at maps.z.b.a(Unknown Source) at maps.s.c.a(Unknown Source) at maps.ab.a.a(Unknown Source) at maps.ab.ax.a(Unknown Source) at maps.as.aw.a(Unknown Source) at maps.w.g.a(Unknown Source) at maps.w.g.b(Unknown Source) at maps.q.p.l(Unknown Source) at maps.q.p.run(Unknown Source)
  26. private void setUpMap() { GoogleMap googleMap = getMap(); if (null

    != googleMap) { onMapInitialized(googleMap); return; } else { try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { return; //no play services -> no map for your user } new MapInitTask().execute(); } } Setting up the map
  27. final class MapInitTask extends AsyncTask<Void, Void, Void> { @Override protected

    Void doInBackground(Void... aVoid) { try { Thread.sleep(125); } catch (InterruptedException e) { //no-op } return null; } ... } The waiting game
  28. final class MapInitTask extends AsyncTask<Void, Void, Void> { ... @Override

    protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); if (null != MyMapFragment.this.getMap()) { //return the map via a listener } else { new MapInitTask().execute(); } } } Are we there yet?
  29. None
  30. Map Markers map.addMarker( new MarkerOptions(...));

  31. Map Markers .position(LatLng) .title(String) .snippet(String)

  32. Map Markers No simple way to set an ID /

    TAG
  33. InfoWindows class MyInfoWindowAdapter implements GoogleMap.InfoWindowAdapter { ... @Override public View

    getInfoContents(Marker marker) { //inflate view, get title and snippet MyData data = displayedData.get(Integer.valueOf(marker.getTitle())); title.setText(data.getTitle()); snippet.setText(data.getSnippet()); return view; } }
  34. Memory management java.lang.OutOfMemoryError: at maps.bl.b.a(Unknown Source) at maps.bl.b.a(Unknown Source) at

    maps.bl.b.a(Unknown Source) at maps.aq.a.a(Unknown Source) at maps.ar.m.b(Unknown Source) at maps.ar.m.a(Unknown Source) at maps.ar.n.a(Unknown Source) at maps.ar.b.run(Unknown Source)
  35. Memory management BitmapDescriptorFactory.from...

  36. Don't blink

  37. No more blinking <FrameLayout ...> <fragment class= "classpath.to.MyMapFragment" ... >

    </FrameLayout> mapHost.requestTransparentRegion(mapHost);
  38. Issue tracker https://code.google.com/p/ gmaps-api-issues/issues

  39. Aftermath What you should keep in mind

  40. It has some rough edges

  41. It evolves

  42. And improves

  43. Aftermath Use it!

  44. Image Sources Google Maps for Android (http://goo.gl/ulb3T) Old VS New

    (http://goo.gl/Hciq6) Getting Started (http://goo.gl/RmYR2) Pitfall (http://goo.gl/fQdZJ) Kittens (http://goo.gl/ectcy) Markers (http://goo.gl/So3kI) Weeping Angel (http://goo.gl/XS8tm) Rough Edges (http://goo.gl/e2Odq) Evolution (http://goo.gl/kWMIU) Improvment (http://goo.gl/gnixN)
  45. Questions Benjamin Weiss http://gplus.to/keyboardsurfer @keyboardsurfer