Java
Need help with trail-android?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
amalChandran

Description

🚕 Simple, smooth animation for route / polylines on google maps using projections.

452 Stars 115 Forks MIT License 102 Commits 11 Opened issues

Services available

Need anything else?

Smooth route animation over Google maps. Uses projection from Google maps to draw a route on an overlay layout. Can add multiple routes with different sytles while supporting pan and zoom of maps.

Build Status Android Arsenal License: MIT

(Gif running @ 10fps. Check the video on youtube.)

|
Overlay polyline
|
Marker and polyline
|
With zoom
| | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: |

Setup

  1. Add jitpack to the root build.gradle file of your project at the end of repositories.
    allprojects {
    repositories {
      ...
      maven { url 'https://jitpack.io' }
    }
    }
    
  2. Add the dependency
    implementation 'com.github.amalChandran:trail-android:v1.51'
    
    ## Usage Place RouteOverlayView over your google map layout in xml. Make sure that the routeoverlayview covers the map completely. This is the view in which the routes will be drawn.
  
  

In your activity, create routes with three predefined styles as of now.

googleMap.setOnMapLoadedCallback(() -> {
    Route normalOverlayPolyline = new Route.Builder(mRouteOverlayView)
        .setRouteType(RouteType.PATH)
        .setCameraPosition(mMap.getCameraPosition())
        .setProjection(mMap.getProjection())
        .setLatLngs(mRoute)
        .setBottomLayerColor(Color.YELLOW)
        .setTopLayerColor(Color.RED)
        .create();

To make sure that the overlay moves along with the Google maps movement we need to add a hook from its cameramovelistener.

googleMap.setOnCameraMoveListener(() -> {
      mRouteOverlayView.onCameraMove(googleMap.getProjection(), googleMap.getCameraPosition());
    }
);
Library uses java 8 bytecode, so dont forget to enable java 8 in your application's build.gradle file.
android {
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

License

MIT © Amal Chandran

Logo

Jibin Joseph

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.