P72B / PolylineAnimator

Android google maps polyline animator library
MIT License
24 stars 4 forks source link

PolylineAnimator

PolylineAnimator

Android google maps polyline animator

A library that will provide an animated polyline object.

There is a medium article explaining the algorithm implementation available.

Import

  1. Add it in your root build.gradle at the end of repositories:
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
  2. Add the dependency
    dependencies {
        implementation 'com.github.p72b:PolylineAnimator:0.1.3'
    }

Implementation

Basic example

     override fun onMapReady(googleMap: GoogleMap) {
         mMap = googleMap

         val animatedPolyline = AnimatedPolyline(
                 mMap,
                 wayPoints
         )
         animatedPolyline.start()
     }

Styled with dotted line and callback to listen on animation events.

    override fun onMapReady(googleMap: GoogleMap) {
        mMap = googleMap

        val animatedPolyline = AnimatedPolyline(
                mMap,
                wayPoints,
                polylineOptions = PolylineOptions()
                                      .color(ContextCompat.getColor(this, R.color.colorPrimary))
                                      .pattern(
                                          listOf(
                                              Dot(), Gap(20F)
                                          )
                                      ),
                duration = 1250,
                interpolator = DecelerateInterpolator(),
                animatorListenerAdapter = object : AnimatorListenerAdapter() {
                                              override fun onAnimationEnd(animation: Animator) {
                                                  animatedPolyline.start() // e.g. endless animation
                                              }
                                          }
        )
        animatedPolyline.startWithDelay(1000)
    }

Library Dependencies:

Benefits:

Requirements

Library: No google API key is required. The library can be used starting at:

Demo App: Android google maps key is required. Runs on:

Download

Check out the lib version on JitPack

Library Sample App

To build the demo app there is an android google maps key needed. Place the key inside app/signing.properties file like this:

GOOGLE_MAPS_API_KEY=key_here

Example of demo app:

DemoApp[default] DemoApp[custom styled]

Animation in video format here