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 full-size slide

  2. @cyrilmottier

    View full-size slide

  3. with
    Google Maps

    View full-size slide

  4. 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 full-size slide

  5. @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 full-size slide

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

    View full-size slide

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

    View full-size slide

  8. 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 full-size slide

  9. For the callout ...
    Good luck !

    View full-size slide

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

    View full-size slide

  11. A lot of code for
    almost nothing

    View full-size slide

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

    View full-size slide

  13. Introduction

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. Feature Overview

    View full-size slide

  20. Gesture support

    View full-size slide

  21. Single tap
    Gesture support

    View full-size slide

  22. Gesture support
    Double tap
    I
    Single tap

    View full-size slide

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

    View full-size slide

  24. 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 full-size slide

  25. Effortless
    Annotations

    View full-size slide

  26. Effortless
    Annotations
    I Auto callout

    View full-size slide

  27. Effortless
    Annotations
    I Auto callout I Variable anchor

    View full-size slide

  28. @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 full-size slide

  29. And others ...

    View full-size slide

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

    View full-size slide

  31. More on Polaris

    View full-size slide

  32. MapCalloutView

    View full-size slide

  33. MapCalloutView
    Title

    View full-size slide

  34. MapCalloutView
    Title
    Subtitle

    View full-size slide

  35. MapCalloutView
    Title
    Subtitle
    Disclosure
    indicator / Right
    accessory

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  38. Do NOT use
    getOverlay()
    Limitations

    View full-size slide

  39. What’s next?

    View full-size slide

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

    View full-size slide

  41. @cyrilmottier
    android.cyrilmottier.com
    Cyril Mottier

    View full-size slide