我正在开发一个微型金融Angular应用程序,因为我正在尝试找到登录到我的应用程序的代理的位置...并且我将详细信息存储在集合中(ActivityDetails)......但是要求是完全不同的。 ..一旦代理登录到我们的应用程序意味着每一小时该位置应该被跟踪并存储在集合中(ActivityDetails)...对于我使用的设置间隔函数....它执行成功但是当我导航到不同的控制器功能没有执行,因为我写入位置跟踪并在导航到差异时在SignIn Controller中存储代码..控制器我面临的问题...如何使这些功能全局运行成功运行一旦登录 并且无论任何控制器。请帮助我找到解决方案....我是Angular的新手,我有3个月的经验...下面我添加功能..请验证并指导我。谢谢你..
///////Signin Controller code for location tracking//////////
$scope.nearme = function(firstname,activity,date,time) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position)
{
lat = position.coords.latitude;
lng = position.coords.longitude;
var latlng = new google.maps.LatLng(lat, lng);
var geocoder = geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
if (results[1])
{
console.log(results[1].formatted_address)
console.log(firstname)
console.log(date)
console.log(time);
var obj={};
obj["User"]=firstname;
obj["Activity"]=activity;
obj["Date"]=$scope.date;
obj["Time"]=$scope.time;
obj["LocationDetails"]=results[1].formatted_address;
console.log(obj)
$http.post("/ncrActivityDetails",obj).success(function(res9){
console.log(res9)
})
}
}
});
});
}
}
/////////////setInterval Function for calling every one hour///////////
setInterval(function(){
$scope.date3 = {date1:new Date()}
$scope.activity="Tracking";
var dates = new Date(((new Date($scope.date3.date1).toISOString().slice(0, 23))+"-05:30")).toISOString();
var a = dates.split("T");
$scope.date = a[0];
$scope.time = a[1];
console.log($scope.date)
console.log($scope.time)
$scope.nearme($scope.firstname,$scope.activity,$scope.date,$scope.time);
},3600000);
////////////////ActivityDetails collection sample data/////////
{
"_id" : ObjectId("5a8a6936fa642a14149a12d1"),
"User" : "7829780519",
"Activity" : "Login",
"Date" : "2018-02-19",
"Time" : "11:35:26.777Z",
"LocationDetails" : "Sri laxmivenkateshwara, #1/10, 4th Main, Srinivasanagar, B S K 3rd Stage, Water Tank Rd, Banashankari 3rd Stage, Banashankari, Bengaluru, Karnataka 560085, India"
}
答案 0 :(得分:0)
解决方案:1)在你的.run模块中创建你的功能,这样当你导航到不同的控制器时它会起作用, check this link
.run(function($interval){
setInterval(function(){
$rootScope.nearme($scope.firstname,$scope.activity,$scope.date,$scope.time);},3600000);});
2)创建服务 - link