<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.2.0-rc2" src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=map&sensor=false"></script>
<script src="angularjs-google-directions.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="mainCtrl">
<img src="https://maps.gstatic.com/mapfiles/api-3/images/powered-by-google-on-white2.png"/>
<h3>Directions Search Example</h3>
<p>{{directions || "loading..."}}</p>
</div>
</body>
</html>
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',
unitSystem: 'imperial'
//unitSystem: 'metric'
}
$scope.directions = googleDirections.getDirections(args).then(function(directions) {
return directions;
});
});
/*! angularjs-google-directions 27-05-2015 */
"use strict";angular.module("dbaq.google.directions",[]),angular.module("dbaq.google.directions").value("googleMaps",google.maps),angular.module("dbaq.google.directions").provider("googleDirections",function(){var a={unitSystem:null,durationInTraffic:!1,waypoints:[],optimizeWaypoints:!1,provideRouteAlternatives:!1,avoidHighways:!1,avoidTolls:!1};this.$get=function(b,c,d,e){function f(f){function g(a,c){b.$apply(c==d.DirectionsStatus.OK||c==d.DirectionsStatus.ZERO_RESULTS?function(){return k.resolve(a)}:function(){return k.reject(c)})}var h=angular.copy(a,{});angular.extend(h,f);var i,j,k=c.defer();return i=h.map?h.map:h.elem?h.elem:e.document.createElement("div"),j=new d.DirectionsService,j.route(h,g),k.promise}var g=[];g.driving=d.TravelMode.DRIVING,g.bicycling=d.TravelMode.BICYCLING,g.transit=d.TravelMode.TRANSIT,g.walking=d.TravelMode.WALKING;var h=[];return h.metric=d.UnitSystem.METRIC,h.imperial=d.UnitSystem.IMPERIAL,{getDirections:function(a){var b=angular.copy(a);return b.travelMode=g[a.travelMode]||d.TravelMode.DRIVING,b.unitSystem=h[a.unitSystem]||d.UnitSystem.METRIC,f(b)}}},this.$get.$inject=["$rootScope","$q","googleMaps","$window"]});
'use strict';
angular.module('dbaq.google.directions', []);
angular.module('dbaq.google.directions').value('googleMaps', google.maps);
angular.module('dbaq.google.directions').
provider('googleDirections', function() {
var defaults = {
unitSystem: null,
durationInTraffic: false,
waypoints: [],
optimizeWaypoints: false,
provideRouteAlternatives: false,
avoidHighways: false,
avoidTolls: false
};
this.$get = function($rootScope, $q, googleMaps, $window) {
var _travelModes = [];
_travelModes['driving'] = googleMaps.TravelMode.DRIVING;
_travelModes['bicycling'] = googleMaps.TravelMode.BICYCLING;
_travelModes['transit'] = googleMaps.TravelMode.TRANSIT;
_travelModes['walking'] = googleMaps.TravelMode.WALKING;
var _unitSystems = [];
_unitSystems['metric'] = googleMaps.UnitSystem.METRIC;
_unitSystems['imperial'] = googleMaps.UnitSystem.IMPERIAL;
function exec(args) {
var req = angular.copy(defaults, {});
angular.extend(req, args);
var deferred = $q.defer();
var elem, service;
function callback(results, status) {
if (status == googleMaps.DirectionsStatus.OK || status == googleMaps.DirectionsStatus.ZERO_RESULTS) {
$rootScope.$apply(function() {
return deferred.resolve(results);
});
} else {
$rootScope.$apply(function() {
return deferred.reject(status);
});
}
}
if (req.map) {
elem = req.map;
} else if (req.elem) {
elem = req.elem;
} else {
elem = $window.document.createElement('div');
}
service = new googleMaps.DirectionsService();
service['route'](req, callback);
return deferred.promise;
}
return {
getDirections: function(args) {
var _args = angular.copy(args);
_args.travelMode = _travelModes[args.travelMode] || googleMaps.TravelMode.DRIVING;
_args.unitSystem = _unitSystems[args.unitSystem] || googleMaps.UnitSystem.METRIC;
return exec(_args);
}
};
};
this.$get.$inject = ['$rootScope', '$q', 'googleMaps', '$window'];
});