Map options doesn't apply when reopening state


#1

have a map in an ionic app that shows a route between user’s current location and a predefined location received from server.

It all works fine on the first try. But when i change the state to something else and come back to the same state. Then none of the map options apply and nothing get drawn on the map.

This maybe something incredibly stupid i might have been doing so any help is appreciated.

The html code is

<ion-view hide-nav-bar="true">
            <ion-content has-footer="true" scroll="false">
            <map id="map" name="Map" center="{{map.center.lat}}, {{map.center.lon}}"></map>
        </ion-content>
</ion-view>

and the controller code is

$scope.map = new google.maps.Map(document.getElementById("map"),
    mapOptions);
var OnCustomerDetailsSuccess = function (resp) {
    if (resp.status == 200) {
        $scope.customer = resp.data;

        var OnLocationSuccess = function (resp) {
            console.log("Location retrieved successfully");


            $scope.directionsDisplay.setMap($scope.map);
            $scope.position.lat = resp.coords.latitude;
            $scope.position.lon = resp.coords.longitude;
            var start = resp.coords.latitude + "," + resp.coords.longitude;
            var end = $scope.customer.pickupLat + "," + $scope.customer.pickupLon;

            var PathSuccess = function(resp){
                console.log("Path retrieved!!!");
                $scope.directionsDisplay.setDirections(resp);
                $ionicLoading.hide();
                pingCheck();
            };

            var PathFailure = function(reason){
                console.log("Error occured while retrieving path");
                $ionicLoading.hide();
            };

            $LocationService.getPath(start, end).then(PathSuccess,PathFailure);


        };


        var OnLocationFailure = function (reason) {
            console.log("Cannot get the location because of ", reason);
            $ionicLoading.hide();
        };
        $LocationService.getLocation().then(OnLocationSuccess, OnLocationFailure);


    }


};

var OnCustomerDetailsFailure = function (reason) {
    $ionicLoading.hide();
};


$ApiService.GetCustomerDetails($scope.rideId).then(OnCustomerDetailsSuccess, OnCustomerDetailsFailure);

Please note that this code works perfectly when the state is opened for the first time, but breaks on subsequently opening it.