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

smdowl/Google-Directions-Android

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google-Directions-Android

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.

Description

When building location based android applications it’s always an added plus to include some form of routing so that the user can know how to navigate from place to place. In android, the SDK does not support routing out of the box. There are several approaches that can be taken to achieve this. You can pass the start and destination points to a Google Maps intent or web view mechanisms. These approaches work well however they are a bit flawed, The user should not have to navigate from the app and the developer has no control once the user navigates to another app therefore this implementation is best. This project utilizes a parser that translate the json received from the directions web service to bunch of geopoints that can be applied to the map control as a route overlay.

Copyright (C) by Joel Dean

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 with these parameters.

new Routing(/*MapView*/,/*Color of line*/).execute(/*LatLng(start)*/,/*LatLng(destination)*/);

actual code

new Routing(mapView,Color.GREEN).execute(new LatLng(18.015365,-77.499382), new LatLng(18.012590,-77.500659));

*Use these parameters if you want a progress dialog to be displayed while the task is running.

new Routing(/*Context*/,/*MapView*/,/*Color of line*/).execute(/*LatLng(start)*/,/*LatLng(destination)*/);

actual code

new Routing(this,mapView,Color.GREEN).execute(new LatLng(18.015365,-77.499382), new LatLng(18.012590,-77.500659));

NEW!!!

*Add a start and destination pushpin to the map using five different colors.Use these parameters if you want a progress dialog to be displayed while the task is running.

new Routing(/*Context*/,/*MapView*/,/*Color of line*/,/*Pushpin color enum*/,/*Pushpin color enum*/ ).execute(/*LatLng(start)*/,/*LatLng(destination)*/);

actual code

new Routing(this,mapView,Color.GREEN,Routing.Start.BLUE, Routing.Destination.ORANGE).execute(new LatLng(18.015365,-77.499382), new LatLng(18.012590,-77.500659));

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.

Developed By

  • Joel Dean
  • Hesham Saeed

For Support

email : [email protected] website : www.joeldeandev.com

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published