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

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

Learnings from using the Google Maps API V2 for Android

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

Benjamin Weiss

June 15, 2013
Tweet

More Decks by Benjamin Weiss

Other Decks in Technology

Transcript

  1. Agenda • A look back • Old VS New •

    Getting started with Maps V2 • Caveats and Pitfalls
  2. Tiles Vector graphics Load paths and render them locally Bitmaps

    Load whole bitmaps and display them locally
  3. 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
  4. Getting started Obtain API keys keytool -list -v -keystore $name

    -alias $name SHA1: f0:00:... keystoreSHA1 + ';' + packageName
  5. 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)
  6. 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
  7. 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
  8. 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?
  9. 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; } }
  10. 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)
  11. No more blinking <FrameLayout ...> <fragment class= "classpath.to.MyMapFragment" ... >

    </FrameLayout> mapHost.requestTransparentRegion(mapHost);
  12. 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)