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

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.

Cyril Mottier

November 13, 2012
Tweet

More Decks by Cyril Mottier

Other Decks in Programming

Transcript

  1. Polaris
    Simple mapping library
    for Android

    View Slide

  2. @cyrilmottier

    View Slide

  3. View Slide

  4. with
    Google Maps

    View Slide

  5. View Slide

  6. View Slide

  7. private static class MyOverlay extends ItemizedOverlay {
    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();
    }
    }

    View Slide

  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));
    }

    View Slide

  9. View Slide

  10. @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...
    mMyLocationOverlay = new MyLocationOverlay(this, mMapView);
    mMapView.getOverlays().add(mMyLocationOverlay);
    }

    View Slide

  11. @Override
    protected void onStart() {
    super.onStart();
    mMyLocationOverlay.enableMyLocation();
    }
    @Override
    protected void onStop() {
    mMyLocationOverlay.disableMyLocation();
    super.onStop();
    }

    View Slide

  12. View Slide

  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

    View Slide

  14. View Slide

  15. For the callout ...
    Good luck !

    View Slide

  16. Good luck !
    For the callout ...
    callout layout, background
    image, onTap on marker,
    callout offset, onTap on map,
    onClick on callout, etc.

    View Slide

  17. A lot of code for
    almost nothing

    View Slide

  18. with
    Polaris

    View Slide

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

    View Slide

  20. Introduction

    View Slide

  21. Demo

    View Slide

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

    View Slide

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

    View Slide

  24. 2
    Import the Polaris Android project
    library in your own project
    http://developer.android.com/tools/projects/
    projects-eclipse.html#ReferencingLibraryProject

    View Slide

  25. 3 Bind onStart() and onStop()
    to PolarisMapView
    @Override
    protected void onStart() {
    super.onStart();
    mPolarisMapView.onStart();
    }
    @Override
    protected void onStop() {
    super.onStop();
    mPolarisMapView.onStop();
    }

    View Slide

  26. 2
    Import the Polaris Android project
    library in your own project
    3
    1 Clone the repository
    Bind onStart() and onStop()
    to PolarisMapView

    View Slide

  27. Feature Overview

    View Slide

  28. Gesture support

    View Slide

  29. Single tap
    Gesture support

    View Slide

  30. Gesture support
    Double tap
    I
    Single tap

    View Slide

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

    View Slide

  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

    View Slide

  33. Annotations

    View Slide

  34. Effortless
    Annotations

    View Slide

  35. Effortless
    Annotations
    I Auto callout

    View Slide

  36. Effortless
    Annotations
    I Auto callout I Variable anchor

    View Slide

  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

    View Slide

  38. And others ...

    View Slide

  39. Built-in “user tracking” mode
    Auto built-in zoom controls
    Natural callouts transitions
    Additional listeners
    And others ...

    View Slide

  40. More on Polaris

    View Slide

  41. MapCalloutView

    View Slide

  42. MapCalloutView
    Title

    View Slide

  43. MapCalloutView
    Title
    Subtitle

    View Slide

  44. MapCalloutView
    Title
    Subtitle
    Disclosure
    indicator / Right
    accessory

    View Slide

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

    View Slide

  46. MapCalloutView
    Disclosure
    indicator / Right
    accessory
    Left
    accessory
    You can even use a custom
    View if you want to

    View Slide

  47. Limitations

    View Slide

  48. Do NOT use
    getOverlay()
    Limitations

    View Slide

  49. What’s next?

    View Slide

  50. Pre-defined markers
    New listeners
    Clustering
    New gestures
    And more ...
    What’s next?

    View Slide

  51. Source code

    View Slide

  52. @cyrilmottier
    android.cyrilmottier.com
    Cyril Mottier

    View Slide