Skip to content

Commit 19a6575

Browse files
author
Marcel Hofmann
committedOct 13, 2015
checkin on map
1 parent 50194bc commit 19a6575

File tree

6 files changed

+72
-7
lines changed

6 files changed

+72
-7
lines changed
 

‎ionic.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
"proxyUrl": "https://9b8ae9df-db6e-44dc-a427-4ef7f194ff97-bluemix.cloudant.com/bluevoo/"
1616
}
1717
]
18-
}
18+
}

‎www/js/controllers/CheckinCtrl.js

+11
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,15 @@ angular.module('bluevoo.controllers')
7676
}
7777
UserSvc.getOwnProfile();
7878
});
79+
80+
modalScope.checkTag = function(tag) {
81+
modelScope.addNew = false;
82+
if (_filter(modalScope.availableTags, function(location) {
83+
return location === tag;
84+
}).length === 0) {
85+
modelScope.addNew = true;
86+
}
87+
88+
return modalScope.tags.tags ? modalScope.tags.tags.length !== 1 : true;
89+
};
7990
});

‎www/js/controllers/MapCtrl.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
angular.module('bluevoo.controllers')
22

3-
.controller('MapCtrl', function(uiGmapGoogleMapApi, $scope, TagSvc) {
3+
.controller('MapCtrl', function(uiGmapGoogleMapApi, $scope, LocationSvc, TagSvc) {
44
angular.extend($scope.map, {
55
zoom: 14
66
});
7+
console.log($scope.map);
8+
$scope.nearbyUsers = [];
79

810
$scope.test = function test() {
9-
$scope.user = TagSvc.locations;
10-
console.log($scope.myPosition);
11+
console.log($scope.map.center);
12+
LocationSvc.getNearbyCheckins().then(function(checkins) {
13+
console.log(checkins);
14+
$scope.nearbyUsers = checkins;
15+
});
1116
};
17+
uiGmapGoogleMapApi.then(function(maps) {
18+
console.log(maps);
19+
});
1220
});

‎www/js/init.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
angular.module('bluevoo')
22
.run(function($ionicPlatform, $rootScope, $cookies, TagSvc, $geolocation, UserSvc) {
3-
$rootScope.map = {};
3+
$rootScope.map = {
4+
center: {
5+
latitude: 50,
6+
longitude: 9
7+
}
8+
};
49
$ionicPlatform.ready(function() {
510
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
611
// for form inputs)
@@ -21,10 +26,14 @@ angular.module('bluevoo')
2126
TagSvc.init();
2227
$geolocation.getCurrentPosition({
2328
timeout: 60000,
24-
enableHighAccuracy: true
29+
enableHighAccuracy: false
2530
}).then(function(position) {
26-
$rootScope.map.center = _.pick(position.coords, ['latitude', 'longitude']);
31+
console.log(position);
32+
$rootScope.map.center.latitude = position.coords.latitude;
33+
$rootScope.map.center.longitude = position.coords.longitude;
2734
$rootScope.myPosition = angular.copy($rootScope.map.center);
35+
}, function(error) {
36+
console.log(error);
2837
});
2938
});
3039

‎www/js/services/LocationSvc.js

+36
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@ angular.module('bluevoo.services')
22

33
.service('LocationSvc', function($http, $q, $rootScope, TagSvc, c) {
44
var _this = this;
5+
_this.nearbyUsers = [];
6+
7+
function getAllCheckIns() {
8+
var deferred = $q.defer();
9+
10+
$http.get(c.url + '_design/design/_view/allCheckins').then(function(response) {
11+
deferred.resolve(response.data.rows);
12+
}, function(error) {
13+
deferred.reject();
14+
});
15+
16+
return deferred.promise;
17+
}
18+
19+
function matchCheckinsWithLocations(checkins, locations) {
20+
var yesterday = new Date().getTime() - 86400000;
21+
return _.map(_.filter(checkins, function(checkin) {
22+
return checkin.value.timestamp*1 > yesterday;
23+
}), function(checkin) {
24+
var location = _.filter(locations, function(location) {
25+
return location.id === checkin.value.location_id;
26+
})[0];
27+
checkin.value.coords = location.value.coords;
28+
return checkin;
29+
});
30+
}
31+
32+
_this.getNearbyCheckins = function() {
33+
var deferred = $q.defer();
34+
getAllCheckIns().then(function(checkins) {
35+
deferred.resolve(matchCheckinsWithLocations(checkins, TagSvc.locations.ibm.concat(TagSvc.locations.customer).concat(TagSvc.locations.hotel)));
36+
}, function() {
37+
deferred.reject();
38+
});
39+
return deferred.promise;
40+
};
541

642
function removeOldCheckin() {
743
var deferred = $q.defer();

‎www/templates/map.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<ion-content>
33
<ui-gmap-google-map center="map.center" zoom="map.zoom">
44
<ui-gmap-marker coords="myPosition" idKey="'pos'"></ui-gmap-marker>
5+
<ui-gmap-marker ng-repeat="user in nearbyUsers" coords="user.value.coords" idKey="user.id"></ui-gmap-marker>
56
</ui-gmap-google-map>
67

78
<hr>

0 commit comments

Comments
 (0)
Please sign in to comment.