-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeoservice.js
More file actions
47 lines (39 loc) · 1.44 KB
/
Copy pathgeoservice.js
File metadata and controls
47 lines (39 loc) · 1.44 KB
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
'use strict';
angular.module('geoService',[])
.factory('geoService',['$q', 'noGeoMessages', function ($q, noGeoMessages){
var deferred = $q.defer(),
watchId;
function watchPosition(track,options){
if (navigator.geolocation) {
if(track)
watchId = navigator.geolocation.watchPosition(showPosition,showError,options || null);
else
navigator.geolocation.getCurrentPosition(showPosition,showError,options || null);
} else
deferred.reject({'error':noGeoMessages[error.code] || "Unknown error code:"+error.code});
return deferred.promise;
}
function showPosition(response) {
//console.log(angular.extend({callback:"position"},{"timestamp":response.timestamp},response.coords));
//deferred.notify(angular.extend({},response.coords,{"timestamp":response.timestamp}));
deferred.notify(angular.extend({},response));
}
function showError(response) {
//console.log(angular.extend({callback:"error"},response));
deferred.notify(angular.extend({},response));
}
function clearWatch(){
//console.log(watchId);
navigator.geolocation.clearWatch(watchId);
}
return {
watchPosition: watchPosition,
clearWatch: clearWatch
};
}])
.value('noGeoMessages',{
PERMISSION_DENIED:"User denied the request for Geolocation.",
POSITION_UNAVAILABLE:"Location information is unavailable.",
TIMEOUT:"The request to get user location timed out.",
UNKNOWN_ERROR:"An unknown error occurred."
});