Is there a way for me to transfer information from one controller to another? Or can I create a service from a controller? Specifically, I am looking to retrieve coordinates and store them in an object along with other variables. When I try to inject dependencies from one controller into another, it doesn't seem to work. The majority of the information in the controller below is irrelevant - all I really need are the latitude and longitude values saved in another controller.
.controller('MapCtrl', function($scope, $cordovaGeolocation, $ionicLoading, $ionicPlatform, $cordovaScreenshot, $ionicPopup) {
$ionicPlatform.ready(function() {
$ionicLoading.show({
template: '<ion-spinner icon="bubbles"></ion-spinner><br/>Acquiring location!'
});
var posOptions = {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0
};
$cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
$scope.duzina = long;
$scope.sirina = lat;
console.log("Širina: " + lat + '\n' + "Dužina: " + long);
var myLatlng = new google.maps.LatLng(lat, long);
var mapOptions = {
center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
$scope.map = map;
$ionicLoading.hide();
var marker = new google.maps.Marker({
animation: google.maps.Animation.DROP,
draggable: true,
label: 'A',
position: myLatlng,
map: map,
title: 'Trenutna Lokacija'
});
var labels = 'BCDEFGHIJKLMNOPQRSTUVWXYZ';
var labelIndex = 0;
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng, map);
});
function addMarker(location, map) {
var marker = new google.maps.Marker({
position: location,
label: labels[labelIndex++ % labels.length],
map: map
});
}
}, function(err) {
$ionicLoading.hide();
console.log(err);
});
})
})