Polaris: simple mapping library for Android

Polaris: simple mapping library for Android

Introduction to Polaris, a library greatly enhancing the features of the Google Maps external library with effortless map annotating, gesture support, map callout support, built-in “user tracking” mode, etc.

Source code: https://github.com/cyrilmottier/Polaris
Sample application: https://play.google.com/store/apps/details?id=com.cyrilmottier.android.polarissample
Blog post: http://android.cyrilmottier.com/?p=824

Presented at the Paris Android Use Group in Paris, France.

E9bf8f6d5480ea2a2623df7dccfd1f70?s=128

Cyril Mottier

November 13, 2012
Tweet

Transcript

  1. Polaris Simple mapping library for Android

  2. @cyrilmottier

  3. None
  4. with Google Maps

  5. None
  6. None
  7. private static class MyOverlay extends ItemizedOverlay<OverlayItem> { public MyOverlay(Context context)

    { super(boundCenterBottom(context .getResources() .getDrawable(R.drawable.map_pin_holed_purple))); } @Override protected OverlayItem createItem(int index) { return sFrance.get(index); } @Override public int size() { return sFrance.size(); } }
  8. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); mMapView =

    (MapView) findViewById(R.id.map_view); mMapView.getOverlays().add(new MyOverlay(this)); }
  9. None
  10. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ... mMyLocationOverlay

    = new MyLocationOverlay(this, mMapView); mMapView.getOverlays().add(mMyLocationOverlay); }
  11. @Override protected void onStart() { super.onStart(); mMyLocationOverlay.enableMyLocation(); } @Override protected

    void onStop() { mMyLocationOverlay.disableMyLocation(); super.onStop(); }
  12. None
  13. 1 FrameLayout with MapView and a Button 2 Style and

    position the Button 3 Set an OnClickListener to the Button 4 Get the current position and center on it
  14. None
  15. For the callout ... Good luck !

  16. Good luck ! For the callout ... callout layout, background

    image, onTap on marker, callout offset, onTap on map, onClick on callout, etc.
  17. A lot of code for almost nothing

  18. with Polaris

  19. mPolarisMapView .setAnnotations( sFrance, R.drawable.map_pin_holed_violet) mPolarisMapView .setUserTrackingButtonEnabled(true);

  20. Introduction

  21. Demo

  22. Source code github.com/cyrilmottier/Polaris Introduction http://android.cyrilmottier.com/?p=824 Sample application http://goo.gl/QBvdW

  23. 1 Clone the repository git clone https://github.com/cyrilmottier/Polaris.git

  24. 2 Import the Polaris Android project library in your own

    project http://developer.android.com/tools/projects/ projects-eclipse.html#ReferencingLibraryProject
  25. 3 Bind onStart() and onStop() to PolarisMapView @Override protected void

    onStart() { super.onStart(); mPolarisMapView.onStart(); } @Override protected void onStop() { super.onStop(); mPolarisMapView.onStop(); }
  26. 2 Import the Polaris Android project library in your own

    project 3 1 Clone the repository Bind onStart() and onStop() to PolarisMapView
  27. Feature Overview

  28. Gesture support

  29. Single tap Gesture support

  30. Gesture support Double tap I Single tap

  31. Gesture support Double tap I Single tap I Long press

  32. mPolarisMapView.setOnMapViewLongClickListener(new OnMapViewLongClickListener() { @Override public void onLongClick(PolarisMapView mapView, GeoPoint geoPoint)

    { // Do whatever you want with this long click that occurred // at the given GeoPoint } }); OnMapViewLongClickListener
  33. Annotations

  34. Effortless Annotations

  35. Effortless Annotations I Auto callout

  36. Effortless Annotations I Auto callout I Variable anchor

  37. @Override public void onAnnotationSelected(PolarisMapView mapView, MapCalloutView calloutView, int position, Annotation

    annotation) { calloutView.setData(annotation); calloutView.setDisclosureEnabled(true); } @Override public void onAnnotationDeselected(PolarisMapView mapView, MapCalloutView calloutView, int position, Annotation annotation) { // Unbind the calloutView from your code } @Override public void onAnnotationClicked(PolarisMapView mapView, MapCalloutView calloutView, int position, Annotation annotation) { startActivity(new Intent(this, AnnotationDetailActivity.class)); } OnAnnotationSelectionChangedListener
  38. And others ...

  39. Built-in “user tracking” mode Auto built-in zoom controls Natural callouts

    transitions Additional listeners And others ...
  40. More on Polaris

  41. MapCalloutView

  42. MapCalloutView Title

  43. MapCalloutView Title Subtitle

  44. MapCalloutView Title Subtitle Disclosure indicator / Right accessory

  45. MapCalloutView Title Subtitle Disclosure indicator / Right accessory Left accessory

  46. MapCalloutView Disclosure indicator / Right accessory Left accessory You can

    even use a custom View if you want to
  47. Limitations

  48. Do NOT use getOverlay() Limitations

  49. What’s next?

  50. Pre-defined markers New listeners Clustering New gestures And more ...

    What’s next?
  51. Source code

  52. @cyrilmottier android.cyrilmottier.com Cyril Mottier