This project allows you to calculate the route between two locations and displays it on a map.

Overview

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

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.
Comments
  • refactor builder

    refactor builder

    I refactored Routing builder class. Please review.

    Example

    Routing routing = new Routing.Builder(start, end)
            .travelMode(AbstractRouting.TravelMode.DRIVING)
            .avoid(AbstractRouting.AvoidKind.HIGHWAYS)
            .waypoints(point1, point2)
            .withListener(this)
            .build();
    routing.execute();
    
    opened by kuwapp 17
  • Add async task cancel listener and multiple waypoint support

    Add async task cancel listener and multiple waypoint support

    1. I have added a callback wrapper for AsyncTask.OnCancelled(), useful if any UI modification is done in the other callbacks (onSuccess/onFailure). If the user moves away from the activity while directions are still being calculated then we can simply discard the results and avoid touching the UI at all.
    2. Added rudimentary support for multiple waypoints as per Using Waypoints in Routes
    opened by deepankarb 17
  • Added the option to select between alternative routes

    Added the option to select between alternative routes

    Added the option to select between alternative routes (shortest, fastest) where RouteMode.FASTEST is the default.

    Usage:

            Routing routing = new Routing.Builder()
                    .travelMode(AbstractRouting.TravelMode.DRIVING)
                    .routeMode(AbstractRouting.RouteMode.SHORTEST)
                    .withListener(this)
                    .waypoints(start, end)
                    .build();
    
    opened by gawdzer 13
  • Wrong results when Bicycling method

    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

    opened by harolhiguera 7
  • Added ability to use a key for the API request

    Added ability to use a key for the API request

    The commit adds the possibility for users to specify their own API key when accessing the Google Directions API, thus enabling more advanced features such as higher quotas and more waypoints.

    To do so the API request must use SSL so the default API URL has been changed to use SSL instead of plain HTTP.

    opened by mkiehl 6
  • support avoid parameters

    support avoid parameters

    hi. Google-Directions-Android is very nice. I will use Google-Directions-Android for my app.

    I support avoid parameters. Please review.

    Example

    Routing routing = new Routing.Builder(Routing.TravelMode.DRIVING)
            .avoid(Routing.AvoidKind.HIGHWAYS)
            .build();
    routing.registerListener(this);
    routing.execute(start, end);
    

    thanks

    opened by kuwapp 6
  • Added some more information about errors on the onRoutingFailure

    Added some more information about errors on the onRoutingFailure

    Currently, the onRoutingFailure callback method does not provide much useful information about the nature of the error. It could be that the API KEY is incorrect, or that the daily quota has been reached, or a bunch of other reasons. The JSON response coming from the Google servers indeed inform the user about the nature of the problem, but the library doesn't relay that information. This commit attempt to fix that.

    PS. I noticed the previous pull request had some useless debug logs, thus I'm submitting another updated pull request.

    opened by bilthon 5
  • A bug fix, a clarified Async task structure

    A bug fix, a clarified Async task structure

    Hello there,

    Please let me thank you for your great library, it saved me a lot of time. I've integrated it yesterday and I discovered a few issues with it.

    I've made a quick patch for bug when the requets is made offline. The InputStream is then null and crashed the parser.

    I have also separated the UI work from the ASync task in Routing.java

    Please feel free to integrate or not these small changes.

    Thanks a lot again for this lib! Cheers, Cyrille

    opened by licryle 4
  • Remove a route?

    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?

    opened by exside 3
  • How to solve gradle syn failed error:(2, 0) defaultmavenfactory

    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"`

    opened by Code1337 2
  • Distance bug

    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

    opened by vincentvanzyl 2
  • Improve GRADLE build Performance

    Improve GRADLE build Performance

    Parallel builds. This project contains multiple modules. Parallel builds can improve the build speed by executing tasks in parallel. We can enable this feature by setting org.gradle.parallel=true.

    Configuration on demand. Configuration on demand tells Gradle to configure modules that only are relevant to the requested tasks instead of configuring all of them. We can enable this feature by setting org.gradle.configureondemand=true.

    gradle caching. Shared caches can reduce the number of tasks you need to execute by reusing outputs already generated elsewhere. This can significantly decrease build times. We can enable this feature by setting org.gradle.caching=true.

    Gradle daemon. The Daemon is a long-lived process that help to avoid the cost of JVM startup for every build. Since Gradle 3.0, Gradle daemon is enabled by default. For an older version, you should enable it by setting org.gradle.daemon=true.

    ===================== If there are any inappropriate modifications in this PR, please give me a reply and I will change them.

    opened by hongdongni 0
  • java.lang.ClassNotFoundException(Api$ClientKey)

    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]

    opened by cpq0329 0
  • Alternatives

    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?

    opened by abduakhatov 1
  • Which License

    Which License

    https://github.com/jd-alexander/Google-Directions-Android shows MIT license in the top right corner (maybe from https://github.com/jd-alexander/Google-Directions-Android/blob/master/LICENSE.md) and at the same time shows Apache 2.0 license at the bottom of that page (from https://github.com/jd-alexander/Google-Directions-Android/blob/master/README.md)

    opened by ross-bradbury 0
Releases(v1.1.0)
Owner
Joel Dean
Cross-Platform Mobile Engineer. Tech Leader. Platforms - Android | iOS | React | React Native | .Net
Joel Dean
This is a repo for implementing Map pan or drag (up, down, right ,left) to load more places on the Google Map for Android

Challenge Display restaurants around the user’s current location on a map ○ Use the FourSquare Search API to query for restaurants: https://developer.

Mahmoud Ramadan 7 Jul 30, 2022
My Maps displays a list of maps, each of which show user-defined markers with a title, description, and location. The user can also create a new map. The user can save maps and load them in from previous usages of the app.

My Maps Bryant Jimenez My Maps displays a list of maps, each of which show user-defined markers with a title, description, and location. The user can

null 0 Nov 1, 2021
An android app that uses Google Maps API and SDK to track a user's location and calculate the total distance travelled

Bike Rush is an android app that uses Google Maps API and SDK to track a user's location and calculate the total distance travelled by him or her along with time and average speed.

Ishant Chauhan 21 Nov 14, 2022
malik dawar 87 Sep 18, 2022
LocationPicker 2.1 0.4 Java - A simple and easy to way to pick a location from map

Introduction LocationPicker is a simple and easy to use library that can be integrated into your project. The project is build with androidx. All libr

Shivpujan yadav 61 Sep 17, 2022
typedmap is an implementation of heterogeneous type-safe map pattern in Kotlin

Typedmap typedmap is an implementation of heterogeneous type-safe map pattern in Kotlin. It is a data structure similar to a regular map, but with two

Ryszard Wiśniewski 34 Nov 7, 2022
Slime loader is a map loader & saver for the file format Slime as specified here implemented in Minestom.

??️ SlimeLoader Slime loader is a map loader & saver for the file format Slime as specified here implemented in Minestom. Features: World loading Bloc

null 25 Oct 2, 2022
Self-hosted map of visited places (with a very fancy stack underneath)

Tripmap Self-hosted map of visited places (with a very fancy stack underneath) Features Sharing custom map-view with pins in locations marked by user.

Igor Kurek 2 Feb 6, 2022
EasyRoutes allows you to easily draw routes through the google maps address api.

EasyRoutes EasyRoutes allows you to easily draw routes through the google maps address api. Note: You need to generate an API key from the google cons

Antonio Huerta Reyes 7 Jul 26, 2022
Android library that allows you to determine your location in a few of lines

locsimple Android library that allows you to determine your location in some lines! Benefits: automatic processing of permissions processing of enabli

Dmitry 7 Aug 31, 2022
Android library project that lets you manage the location updates to be as painless as possible

Smart Location Library Android library project that intends to simplify the usage of location providers and activity recognition with a nice fluid API

Nacho Lopez 1.6k Dec 29, 2022
Positional is a location information app for Android with Compass, Clock, Level, Sun and Moon and many other features.

Positional is a location based app that utilizes the device's GPS and fetches various details of the current latitude and longitude data like Altitude, Speed, Address and similar other information and show it in easily understandable format to the user. Alongside this main functionality of being a location app, Positional also provides a separate panel for Compass and Clock, and they serve their own purpose as their name suggests.

Hamza Rizwan 85 Dec 28, 2022
🍃 Organic Maps is an Android & iOS offline maps app for travelers, tourists, hikers, and cyclists based on top of crowd-sourced OpenStreetMap data and curated with love by MapsWithMe founders.

?? Organic Maps is an Android & iOS offline maps app for travelers, tourists, hikers, and cyclists based on top of crowd-sourced OpenStreetMap data and curated with love by MapsWithMe founders. No ads, no tracking, no data collection, no crapware.

Organic Maps 4.3k Dec 31, 2022
Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.

Mapbox 247 Dec 27, 2022
Google Maps Api test using marker rotation and routes.

Google Maps Api test using marker rotation and routes. Features ✔️ Kotlin ✔️ DI: Hilt ✔️ Retrofit ✔️ Gson ✔️ View binding ✔️ Coroutines ✔️ AndroidX ✔️

Carlos Adan 39 Jul 15, 2022
Dual Camera, IMU, and GPS data recorder for Android

Dual Camera, IMU, and GPS data recorder for Android

AUT 3D Vision 17 Oct 24, 2022
The app has got fullscreen Turkey map via Huawei Map. App selects random province and shows it borders on the map than user will try to guess the provinces name.

Il Bil App Introduction I will introduce you to how to implement Account Kit, Map Kit, Game Service. About the game: The app has got fullscreen Turkey

Gökhan YILMAZ 4 Aug 2, 2022
Tree View; Mind map; Think map; tree map

A custom tree view for Android, designed for easy drawing some tree nodes (e.g. thind mind and tree nodes). Includes smoothly zoom, move, limit and center fix animation support, and allows easy extension so you can add your own child node's customs view and touch event detection.

怪兽N 304 Jan 3, 2023
Project BlueWeather is an android app that lists the closest locations to you and shows the 7-day weather forecast for the location you select.

Project BLUEWEATHER Description Project BlueWeather is a weather forecast application for android. It lists the locations closest to you. It then prov

Burak Unutmaz 4 May 12, 2021
Map-vs-list-comparator - The project compares the time needed to find a given element in a map vs the time needed to find a given element in a list.

Map vs List Comparator The project compares the time needed to find a given element in a map vs the time needed to find a given element in a list. To

null 0 Jan 4, 2022