An angular.js wrapper around the Google Directions API (heavily inspired by AngularJS-Google-Places)
This module is available as bower package, install it with this command:
bower install angularjs-google-directions
or
bower install git://github.com/dbaq/angularjs-google-directions.git
See this plunker
- Include the Google Maps JS library in your app
- Add dbaq.google.directions as a dependency
- Inject googleDirections as a dependency to your controller or other service
- Invoke the getDirections method and pass in an origin and a destination
var myApp = angular.module('myApp', ['dbaq.google.directions']);
myApp.controller('mainCtrl', function($scope, googleDirections) {
var args = {
origin: '37.7738571,-122.4102823',
destination: '37.7891231,-122.4173545',
travelMode: 'bicycling'
}
$scope.directions = googleDirections.getDirections(args).then(function(directions) {
return directions;
});
});
You can override any default option below by passing that property to the getDirections method
var defaults = {
unitSystem: null,
durationInTraffic: false,
waypoints: [],
optimizeWaypoints: false,
provideRouteAlternatives: false,
avoidHighways: false,
avoidTolls: false,
travelMode: 'driving', // bicycling, transit, walking
unitSystem: 'metric', // imperial
};
If your app is successful or if you are working for a company, please consider donating some beer money 🍺:
Keep in mind that I am maintaining this repository on my free time so thank you for considering a donation. 👍
TODO
MIT