Giter Club home page Giter Club logo

google-directions-android's Introduction

Google-Directions-Android

Maven Central Android Arsenal Build Status

This project allows you to calculate the direction between two locations and display the route on a Google Map using the Google Directions API - This project isn't actively been maintained.

Example Image

Sample

The sample makes use of the Google Places API for Android in order to provide a real life example of how the library can be used.You can check it out on the store.

Download

Grab via Maven:

<dependency>
  <groupId>com.github.jd-alexander</groupId>
  <artifactId>library</artifactId>
  <version>1.1.0</version>
</dependency>

or Gradle:

    compile 'com.github.jd-alexander:library:1.1.0'

Usage

To calculate the route you simply instantiate a Routing object and trigger the execute function.

*You can execute the task in this manner. ( See the example for more details on the exact implementation)

        Routing routing = new Routing.Builder()
                    .travelMode(/* Travel Mode */)
                    .withListener(/* Listener that delivers routing results.*/)
                    .waypoints(/*waypoints*/)
                    .key(/*api key for quota management*/)
                    .build();
        routing.execute();
        

actual code

        start = new LatLng(18.015365, -77.499382);
        waypoint= new LatLng(18.01455, -77.499333);
        end = new LatLng(18.012590, -77.500659);
        
        Routing routing = new Routing.Builder()
                    .travelMode(Routing.TravelMode.WALKING)
                    .withListener(this)
                    .waypoints(start, waypoint, end)
                    .build();
        routing.execute();
        
        .....
        
       @Override
    public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex)
    {
       //code to add route to map here. See sample app for more details.
    }

Demostration

Demo App

Known Issues

  • If the AutoComplete TextView/Map of the sample app isnt working then probably the API key hasn't been set in the manifest.

  • If the route is not being displayed then type "Routing" in your log cat to see the potential error messages from the library.

Contribution

Please fork repository and contribute using pull requests.

Any contributions, large or small, major features, bug fixes, additional language translations, unit/integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.

Contributors

License

Copyright 2016 Joel Dean

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

google-directions-android's People

Contributors

bilthon avatar bitdeli-chef avatar buddhikadesilva avatar fcduarte avatar fgil avatar furkantektas avatar jd-alexander avatar joaopedronardari avatar ksarmalkar avatar kuwapp avatar licryle avatar nevstad avatar nhkhanh avatar vincenzoiacovone avatar yusufiga 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  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

google-directions-android's Issues

Remove a route?

Is it somehow possible to remove a route when another marker on a map is clicked? I have 9 markers to which the route from the current position can be asked by the user, but they just add up on top of each other (depending on the route/location). I would like to display just the route to the last clicked marker...tried to assign the Routing to a variable and then set this to null onMarkerClick but that didn't work. Any hints?

Cannot resolve prediction.getDescription

I try to run your project in android studio. but when I search location in AutoCompleteTextView, show me this error : "Cannot resolve prediction.getDescription":
how can fix this problem and show locations name description when write location names ?

LatLng[ ] on a waypoints not working

Hi!
When I want to create my route with some points (sometimes two points and sometimes more points) I put a LatLng array with all its points but it crashes. How can I solve this problem.

Thanks

Possible to implement optimize:true?

In Google Direction API, there is a way for Google to calculate the best route to pass through all waypoints in an effective way to destination. Which can be easily done by adding "optimize:true" before adding all waypoints, can you consider adding a variable for easier insertion?

Alternatives

Inside the code there is request asking "&alternatives=true" but it is not showing multiple routes(I mean alternative routes). Is it bug or shall I implement something?

Wrong results when Bicycling method

Hi Jd Alexander,

Thanks a lot for taking the time to build this library, it saved me a lot of time, I have a problem..it seems that the route retrieved for cycling method is the same as driving method, anyhow it does not coincide with the google maps app route.. According to the documentation the key work for transport method is "bicycling".. you have in your library declared biking, I wonder if that is the reason why.

Cheers

java.lang.ClassNotFoundException(Api$ClientKey)

hei,I clone your project,but i doesn't run. can you help me? there are some tips:
Process: com.directions.sample, PID: 24051
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$ClientKey;
at com.google.android.gms.location.places.Places.(Unknown Source)
at com.directions.sample.MainActivity.onCreate(MainActivity.java:82)
at android.app.Activity.performCreate(Activity.java:6910)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.api.Api$ClientKey" on path: DexPathList[[zip file "/data/app/com.directions.sample-2/base.apk"],nativeLibraryDirectories=[/data/app/com.directions.sample-2/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.android.gms.location.places.Places.(Unknown Source) 
at com.directions.sample.MainActivity.onCreate(MainActivity.java:82) 
at android.app.Activity.performCreate(Activity.java:6910) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:156) 
at android.app.ActivityThread.main(ActivityThread.java:6523) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) 
05-15 17:52:06.538 620-877/? E/logserver: imonitor_add_dynamic_path, path:/data/system/dropbox/[email protected]

Unable to run project,downloaded zip

I have downloaded the zip file and after extraction I imported into android studio but I got this error.Somebody help me please.

Error:(2, 0) Cause: org/gradle/api/publication/maven/internal/DefaultMavenFactory
Open File

Example not working anymore

Hi,

first of all, thanks for that library, does a great job and saves time!

I noticed, that I have to revert around 2 commits back to make it work with the code provided in the example, seems to be a problem with resent changes in the Routing class, could that be?

Error

JSONException while parsing RouteException argument. Msg: No value for error_message

This error keeps coming .
My server key is valid .

Do not work AutoComplete

I clone you project in android studio. but when search location in AutoCompleteTextView, show me this error : Error contacting API:
how can fix this problem and show locations when write location names ?

Optimize is not working

Hi,
I try to use optimize(true) in the routing builder and it does not seem to work. I try to find the shortest route if I start from point A and want to visit B, C,D and E. The order of visiting does not matter.
Any ideas?

java.lang.NullPointerException

Apparently shortestRoute is initialized in null when:

result != null but is 0
//Line 99 in AbstractRouting class
i$ = shortestRoute.getPoints().iterator(); // at this point shortestRoute is null
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.directions.route.Route.getPoints()' on a null object reference
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at com.directions.route.AbstractRouting.onPostExecute(AbstractRouting.java:146)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at com.directions.route.AbstractRouting.onPostExecute(AbstractRouting.java:20)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at android.os.AsyncTask.finish(AsyncTask.java:636)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at android.os.AsyncTask.access$500(AsyncTask.java:177)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
10-08 15:02:07.212 6045-6045/ai.home E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Zooming does not make the path to zoom as well

Hello ,

It is a good library to use in the app. But I noticed a thing about it that
I used it in my app and figured out that it draws a line between two points , but when I zoom the map, the line drawn stays at same location .

can this be solved ?
please let me know.

Directions: wishes to retrieve the set of instruction texts

I created one anyway.

public String[] getDirectionTexts(Document doc) {
    NodeList nl1, nl2;

    nl1 = doc.getElementsByTagName("step");
    String[] instructions = null;
    if (nl1.getLength() > 0) {
        instructions = new String[nl1.getLength()];
        for (int i = 0; i < nl1.getLength(); i++) 
        {
            Node node1 = nl1.item(i);
            nl2 = node1.getChildNodes();

            Node locationNode = nl2.item(getNodeIndex(nl2, "html_instructions"));
            instructions[i] = Html.fromHtml(locationNode.getTextContent()).toString();
            if(isLogging)
                Log.i("GoogleDirection", "Instructions : " + Html.fromHtml(locationNode.getTextContent()).toString());
        }
    }
    return instructions;
}    

in GoogleDirection.java

Thank you for your awesome work. Accept this as a sign of my gratitude

Issue when using the gradle library and the RoutingListener

I am having the problem of when using the RoutingListener and trying to overide the

public void onRoutingSuccess(ArrayList route, int shortestRouteIndex) in my class.. A the ArrayList route, I keep getting expression expected. I am using the example attached with the repo and also declared ArrayList route; Please help

More than Two location

can this library tracking more than two location , i mean create route from my ordered list of latlang ?

Distance bug

Hi

On line 91 on your GoogleParser class:
segment.setDistance(distance / 1000);

distance is and int and 1000 is also an int and the segment distance is a double. And as a consequence, the distances are not calculated correctly. I have values like 0.0, 1.0, 9.0, etc

You need to cast both to doubles:
segment.setDistance((double)distance / (double)1000);

Thanks for a great library

Wrong results when Bicycling method

Hi Jd Alexander,

Thanks a lot for taking the time to build this library, it saved me a lot of time, I have a problem..it seems that the route retrieved for cycling method is the same as driving method, anyhow it does not coincide with the google maps app route.. According to the documentation the key work for transport method is "bicycling".. you have in your library declared biking, I wonder if that is the reason why.

Cheers

How to solve gradle syn failed error:(2, 0) defaultmavenfactory

I am getting this error during gradle syn - Error:(2, 0) org/gradle/api/publication/maven/internal/defaultmavenfactory

error focus onto this
`apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: "com.jfrog.bintray"

dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
// This is the library version used when deploying the artifact
version = "1.0.9"`

Sample app doesn't work with maps api v2

adding overlays in below fashion doesn't work with maps api v2
//map.getOverlays().add(routeOverlay);
//map.invalidate();

Please implement it using Marker class.
I'm beginner in android and struggling to make it work

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.