Skip to content

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

License

Notifications You must be signed in to change notification settings

felixvolz/Google-Directions-Android

 
 

Repository files navigation

Google-Directions-Android Bitdeli Badge

This project allows you to calculate the direction between two locations and display the route on a map based on the classes created by Hesham Saeed in this post.

Sample

A map with route overlay.

Example Image

Installation

The sample project requires:

  • The library project
  • Google Play services SDK (bundled with project)
  • android-support-v4-jar (bundled with project)
  • Android dependencies installed on your development machine.

Usage

Google Directions Android(the library folder) is presented as an Android library project. You can include this project by referencing it as a library project in Eclipse or ant.

For the library project a reference has to be done to the Google Play Services Lib project that contains the Google Maps Android API v2 dependencies.

To calculate the route and display it on the map you will need to run an async task that is present in the library.

N.B Ensure that the google play servicers jar is attached to the Google Play Services lib project.

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

        Routing routing = new Routing(/* Travel Mode */);
        routing.registerListener(/* Listener that delivers routing results.*/);
        routing.execute(/*LatLng(start)*/, /*LatLng(destination)*/);
        

actual code

        start = new LatLng(18.015365, -77.499382);
        end = new LatLng(18.012590, -77.500659);
        
        Routing routing = new Routing(Routing.TravelMode.WALKING);
        routing.registerListener(this);
        routing.execute(start, end);
        
        .....
        
      @Override
      public void onRoutingSuccess(PolylineOptions mPolyOptions) 
      {
        PolylineOptions polyoptions = new PolylineOptions();
        polyoptions.color(Color.BLUE);
        polyoptions.width(10);
        polyoptions.addAll(mPolyOptions.getPoints());
        map.addPolyline(polyoptions);
      }

*The library is bundled with start and end pushpins of various colours, check the example included or just have a look in the res folder.

Known Issues

*If after importing the project(s) you get an error stating that no resource was found that matches a given name, just clean the project.

*Ensure that the Google Play Services SDK is attached to the libary project and that all references and values are in your manifest.

*For the example project it needs android-support-v4-jar due to use of the elements from the support library.

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

*The color is of type int, its not an actual color. Just type Color. and wait for the intellisense the to suggest the colors.

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

Cyrille Berliat

Developed By

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published