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. 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(); } }
  2. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ... mMyLocationOverlay

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

    void onStop() { mMyLocationOverlay.disableMyLocation(); super.onStop(); }
  4. 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
  5. Good luck ! For the callout ... callout layout, background

    image, onTap on marker, callout offset, onTap on map, onClick on callout, etc.
  6. 2 Import the Polaris Android project library in your own

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

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

    project 3 1 Clone the repository Bind onStart() and onStop() to PolarisMapView
  9. 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
  10. @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