-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
67 lines (62 loc) · 2.29 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var app = angular.module('myApp', ['google-maps',"firebase"]);
app.controller('MainCtrl',['$scope','$firebaseArray', function($scope,$firebaseArray ) {
$scope.map = {
control: {},
center: {
latitude: -37.812150,
longitude: 144.971008
},
zoom: 14
};
$scope.marker = {
center: {
latitude: -37.812150,
longitude: 144.971008
}
};
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
var geocoder = new google.maps.Geocoder();
console.log("$scope.directions",$scope.origin);
console.log("$scope.destination",$scope.destination);
$scope.location=[];
$scope.showList=false;
$scope.getDirections = function () {
console.log("$scope.directions",$scope.origin);
console.log("$scope.destination",$scope.destination);
$scope.showList =true;
var request = {
origin: $scope.origin,
destination: $scope.destination,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
directionsDisplay.setMap($scope.map.control.getGMap());
directionsDisplay.setPanel(document.getElementById('directionsList'));
} else {
alert('Google route unsuccesfull!');
}
});
};
var ref= firebase.database().ref().child('locations');
$scope.locations = $firebaseArray(ref);
$scope.addItem=function ()
{
var values = {};
values.origin = $scope.origin;
values.destination = $scope.destination;
$scope.locations.$add(values).then (function (data) {
console.log("data",data);
}),function (err) {
console.log("err",err);
}
};
$scope.$on('gmPlacesAutocomplete::placeChanged', function(){
var location = $scope.origin.getPlace().geometry.location;
$scope.lat = location.lat();
$scope.lng = location.lng();
$scope.$apply();
});
}]);