I have two tabs: Maps and Places
The problem is that every time I go the Maps tab, the Google Maps it is loaded whether is already loaded before. This causes my app to slow down, every time I go to the Maps Tab
I tried to make this logic my MapCtrl
if ($scope.map == undefined) {
console.log('NO GOOGLE MAP');
var mapOptions = {
center: usersLatLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$cordovaGeolocation.getCurrentPosition(options).then(function(position){
$scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
}
} else {
console.log('HAS GOOGLE MAP');
}
The result in the console every time I go to the Maps Tab is 'NO GOOGLE MAP'
Is there anyway to trigger the else function when the Google Maps is already defined?
Example would be when I move from MAPS->PLACES->MAPS, the Google Map won't load anymore.
答案 0 :(得分:2)
我通过在我的状态中添加 cache:true 来解决问题。
.state('tab.map', {
url: '/map',
cache:true,
views: {
'tab-map': {
templateUrl: 'templates/tab-map.html',
controller: 'MapCtrl'
}
},
params: { args: {} }
})