这是我的第一个离子应用程序。 我想我有一个内存泄漏问题,这是我的代码:
app.controller('ArtistsCtrl', ['$scope', '$cordovaGeolocation', '$ionicLoading', '$http', '$ionicPlatform', '$rootScope', 'UserService', '$timeout', function($scope, $cordovaGeolocation, $ionicLoading, $http, $ionicPlatform, $rootScope, UserService, $timeout) {
var posOptions = {timeout: 20000, enableHighAccuracy: true, maximumAge: 36000};
function gps(posOptions)
{
$scope.searching = true;
$cordovaGeolocation.getCurrentPosition(posOptions).then(function(position) {
$scope.searching = false;
// var lat = position.coords.latitude,
// long = position.coords.longitude;
var lat = 40.821216,
long = -73.942684;
console.log(lat, long);
json_url = ('https://maps.googleapis.com/maps/api/geocode/json?latlng='+ lat +','+ long + '&key=123456789');
$http.get(json_url).then(function(response) {
// console.log(response.data);
$ionicLoading.hide();
$scope.address = response.data;
var address_components = $scope.address.results[0].address_components,
levels_arr = [];
// United States
for(var i = 0; i < address_components.length; i++){
if(address_components[i].types[0] == 'locality'){
levels_arr.push(address_components[i]);
}else if(address_components[i].types[0] == 'sublocality'){
levels_arr.push(address_components[i]);
}else if(address_components[i].types[0] == 'neighborhood'){
levels_arr.push(address_components[i]);
}else if(address_components[i].types[0] == 'political'){
levels_arr.push(address_components[i]);
console.log(address_components[i]);
var nyc = ['Bronx', 'Manhattan', 'Staten Island', 'Queens', 'Brooklyn'];
for(var i = 0; i < 5; i++){
if(inArray(address_components[i].long_name, nyc)){
levels_arr.push({long_name: "New York City", short_name: "New York City", types: ["locality"]});
}
}
}
};
console.log(levels_arr);
var locations = valuesToArray(levels_arr);
var levels = [];
var positions = [];
for(var i = 0; i < levels_arr.length; i++){
levels[i] = locations[i]['types'][0];
positions[i] = locations[i]['short_name'];
// console.log(positions[i]);
if(positions[i] == 'Upper Manhattan'){
positions[i] = 'Harlem';
}else{
positions[i] = locations[i]['short_name'];
}
}
$scope.tabs = [];
$scope.artistslist = [];
for(var i=0;i<positions.length;i++){
$scope.tabs.push({"position" : i, "text" : positions[i]});
}
if($scope.tabs.length > 0){
$scope.tablebox = true;
}
console.log('niveaux et valeurs',levels, positions);
// we fill every levels with artists
if(levels[0] && positions[0]){
$scope.hasMoreData0 = true;
$scope.artistslist0 = [];
var page = 2;
$scope.populateList0 = function() {
$scope.spin = true;
$http.get('api?level='+levels[0]+'&value='+positions[0]+'&p='+page).then(function(response){
page++;
console.log(response);
$scope.spin = false;
if(response.data.length > 0){
angular.forEach(response.data, function(response){
$scope.artistslist0.push(response);
});
}else{
$scope.hasMoreData0 = false;
}
});
$scope.$broadcast('scroll.infiniteScrollComplete');
};
$http.get('api?level='+levels[0]+'&value='+positions[0]).then(function(response){
$scope.artistslist0 = response.data;
console.log('0',response.data);
});
}
if(levels[1] && positions[1]){
$scope.artistslist1 = [];
$scope.hasMoreData1 = true;
var page = 2;
$scope.populateList1 = function() {
$scope.spin = true;
$http.get('api?level='+levels[1]+'&value='+positions[1]+'&p='+page).then(function(response){
page++;
console.log(response);
$scope.spin = false;
if(response.data.length > 0){
angular.forEach(response.data, function(response){
$scope.artistslist1.push(response);
});
}else{
$scope.hasMoreData1 = false;
}
});
$scope.$broadcast('scroll.infiniteScrollComplete');
};
$http.get('api?level='+levels[1]+'&value='+positions[1]).then(function(response){
$scope.artistslist1 = response.data;
console.log('1', response.data, 'api?level='+levels[1]+'&value='+positions[1]);
});
}
if(levels[2] && positions[2]){
$scope.hasMoreData2 = true;
$scope.artistslist2 = [];
var page = 2;
$scope.populateList2 = function() {
$scope.spin = true;
$http.get('api?level='+levels[2]+'&value='+positions[2]+'&p='+page).then(function(response){
page++;
$scope.spin = false;
if(response.data.length > 0){
angular.forEach(response.data, function(response){
$scope.artistslist2.push(response);
});
}else{
$scope.hasMoreData2 = false;
}
});
$scope.$broadcast('scroll.infiniteScrollComplete');
};
$http.get('api?level='+levels[2]+'&value='+positions[2]).then(function(response){
$scope.artistslist2 = response.data;
console.log('2', response.data, 'api?level='+levels[2]+'&value='+positions[2]);
});
}
});
}, function(err) {
$scope.allowRefresh = true;
console.log(err);
});
}
$scope.updateMyPosition = function(){
var onSuccess = function(position) {
console.log('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
};
// onError Callback receives a PositionError object
function onError(error) {
console.log('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
if(gps(posOptions)){
console.log('fire !!');
}
$scope.$broadcast('scroll.refreshComplete');
};
$scope.gps = gps(posOptions);
var watchOptions = {timeout : 3000, enableHighAccuracy: false};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
null,
function(err) {
console.log(err);
},
function(position) {
var lat = position.coords.latitude,
long = position.coords.longitude;
console.log(lat + '' + long);
// alert(lat + '' + long);
}
);
watch.clearWatch();
}]);
朋友开发,跟我谈过内存泄漏,我做了一些研究,但没有具体的...... 我无法找到它的位置..欢迎任何帮助,谢谢你们!