a0fba7c8
David Beech
david
|
1
|
(function(angular) {
|
ec938bf0
Tarpit Grover
first commit
|
2
3
|
var app = angular.module('batmanDelivers');
app.directive("addressSearch", addressSearch);
|
a0fba7c8
David Beech
david
|
4
|
addressSearch.$inject = ['$parse', '$rootScope', '$http', '$timeout', '$sce']
|
ec938bf0
Tarpit Grover
first commit
|
5
|
|
a0fba7c8
David Beech
david
|
6
|
function addressSearch($parse, $rootScope, $http, $timeout, $sce) {
|
ec938bf0
Tarpit Grover
first commit
|
7
8
|
return {
templateUrl: '/src/js/directives/address-search/partial.html',
|
a0fba7c8
David Beech
david
|
9
10
11
12
|
replace: true, //study
transclude: true, //study
link: function(scope, elm, attrs) {
|
ec938bf0
Tarpit Grover
first commit
|
13
|
scope.placeholder = attrs["placeholder"];
|
a0fba7c8
David Beech
david
|
14
15
16
17
|
scope.address = $parse(attrs['model'])(scope);
scope.order = $parse(attrs['order'])(scope);
scope.lbl = $parse(attrs['lbl'])(scope);
|
484036e0
Tarpit Grover
WIP
|
18
19
20
|
scope.request = function(value){
|
a0fba7c8
David Beech
david
|
21
22
|
if (value && value.length > 3) {
$http({
|
484036e0
Tarpit Grover
WIP
|
23
|
dataType: 'jsonp',
|
a0fba7c8
David Beech
david
|
24
25
26
27
28
29
30
31
32
|
method: "GET",
url: "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" + value + "&key=AIzaSyAPYatPrCcmNcVdAO_MF0YhO3c1mgdLvuQ"
}).then(function mySuccess(response) {
scope.addresses = response.data.predictions;
}, function myError(response) {
scope.error = response.statusText;
});
}
}
|
a668a573
Sean Wills
new
|
33
|
|
ec938bf0
Tarpit Grover
first commit
|
34
|
scope.selectAddress = function(place) {
|
a0fba7c8
David Beech
david
|
35
36
37
38
39
40
41
42
43
44
45
46
47
|
$http({
method: "GET",
url: "https://maps.googleapis.com/maps/api/place/details/json?placeid=" + place.place_id + "&fields=geometry,adr_address,address_component,formatted_address&key=AIzaSyAPYatPrCcmNcVdAO_MF0YhO3c1mgdLvuQ"
}).then(function mySuccess(response) {
scope.result = response.data.result;
scope.address = {
AddressLine1: scope.result.address_components[1].long_name,
AddressLine2: scope.result.address_components[2].long_name,
City: scope.result.address_components[3].long_name,
PostCode: scope.result.address_components[0].long_name,
Latitude: scope.result.geometry.location.lat,
Longitude: scope.result.geometry.location.lng,
|
a0fba7c8
David Beech
david
|
48
|
Description: place.description
|
ec938bf0
Tarpit Grover
first commit
|
49
|
}
|
ec938bf0
Tarpit Grover
first commit
|
50
|
|
a0fba7c8
David Beech
david
|
51
52
53
54
55
56
57
58
|
}, function myError(response) {
scope.error = response.statusText;
});
}
}
}
}
})(angular);
|
ec938bf0
Tarpit Grover
first commit
|
|
|
a668a573
Sean Wills
new
|
|
|