Coder Social home page Coder Social logo

amalchandran / trail-android Goto Github PK

View Code? Open in Web Editor NEW
508.0 25.0 128.0 67.8 MB

๐Ÿš• Simple, smooth animation for route / polylines on google maps using projections.

License: MIT License

Java 99.89% Kotlin 0.11%
android animator google-maps polyline uber canvas projection animation animations arc

trail-android's Introduction

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' }
    }
}
  1. 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.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment"/>
  <com.amalbit.trail.RouteOverlayView
    android:id="@+id/mapOverlayView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</FrameLayout>

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

trail-android's People

Contributors

amalbit avatar amalchandran avatar carotkut94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trail-android's Issues

Sometime It doesn't work

Thank for your supporting. Anyway, I got some issues, My app running perfect but Sometime I could not draw any line on the map. I don't know why my map was loaded done but the line did not appear.

Anyone who get the same error just hit the ideas below.

Thank you!

In Uber path is above text.

Hey thank you fro great code, i want to know one thing. In uber poly line path is above the text, but using your code the path is showing below the code.

any hint??

Drawing goes wrong sometimes

Hi,
Thanks for your great library. i was looking at demo and saw that the driving isn't correct on emulator. See below gif.
ezgif com-video-to-gif 1

R8 removes the code

Enabling R8 clears out the code and it doesn't work. I think this happens due to the following line since that line doesn't have a strong reference.

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

can't start projection based route

hi there !
first of all thank you for your great library :)
when i start projection based route i have this error :

Attempt to invoke interface method 'java.lang.ref.WeakReference com.amalbit.trail.contract.GooglemapProvider.getGoogleMapWeakReference()' on a null object reference

i just want to have polyline like this with effect and animation

Quality Issue

Hi and thanks for creating this lib.
there is a problem which I need to fix....when you zoom in too much you'll see the quality of the line decreases since that is a view and it is scaling...but this is not the case in Uber.
how can we fix this issue?
and there is also flickering issue when trying to draw the line in the beginning of the animation...

any help would be appreciated

Two routes error

When only two routes lib throwing exception, seems wrong condition. (builder.latLngs.size() <= 2)

else if (builder.latLngs == null || builder.latLngs.isEmpty() || builder.latLngs.size() <= 2) {
throw new NullPointerException("LatLngs cannot be null or then count less than 2.");
}

java.lang.ArithmeticException

java.lang.ArithmeticException - divide by zero
Fatal Exception: java.lang.ArithmeticException: divide by zero
at com.amalbit.trail.RouteOverlayView.calculateDimensionForDebugGrid(RouteOverlayView.java:25)
at com.amalbit.trail.RouteOverlayView.onSizeChanged(RouteOverlayView.java:25)
at android.view.View.sizeChange(View.java:23773)
at android.view.View.setFrame(View.java:23725)
at android.view.View.layout(View.java:23577)
at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:389)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:389)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:46)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1857)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1846)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1612)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:389)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:389)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:46)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:334)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1857)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1701)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1610)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:334)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1857)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1701)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1610)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:334)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:1141)
at android.view.View.layout(View.java:23580)
at android.view.ViewGroup.layout(ViewGroup.java:6647)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4869)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4251)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2828)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10506)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1623)
at android.view.Choreographer.doCallbacks(Choreographer.java:1141)
at android.view.Choreographer.doFrame(Choreographer.java:1012)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1585)
at android.os.Handler.handleCallback(Handler.java:955)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:206)
at android.os.Looper.loop(Looper.java:296)
at android.app.ActivityThread.main(ActivityThread.java:8971)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:569)
at com.android.internal.os.ZygoteInit

database values into array list

i am storing latitude and longitude values in database for every 30 sec.how can i pass those stored values into arraylist

Several build issues

There are several issues that stop this repository from being built by only running ./gradlew installDebug

  1. trails module is missing build.gradle
    Solution: add the missing build.gradle file

  2. ./gradlew is looking for the gradle wrapper jar which doesn't exists
    Solution: add gradle folder with wrapper configuration

  3. local.properties points to your development environment cause the command to fail as the sdk is not located in the given directory.
    Solution: remove the local.properties file

Looking forward to test the sample
Cheers

How to use this library

Hi, I have used your library from the first version. Recently we have changed the code, so I could not find out to use it and implement the path to my map. Can you update readme with clear document, please!

Thank you so much!

polyline flickering

Whenever path is drawn polyline is flickering at the end. But when zooming in polyline seems to be ok. Looks like map is auto adjusting the polyline. Any solution?

Issue when zoom in zoom out or move map

Thank you for your library.
I got some issue with path when zoom , move map. All path will display wrong place where they should display first. It like a overlayview does not match with location in map. I think that.

Just check it out and find some solutions.
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.