Map options doesn't apply when reopening state

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>

and the controller code is

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

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

            $ = 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!!!");

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

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


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



var OnCustomerDetailsFailure = function (reason) {

$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.