Passing values between functions


#1

i’m trying to pass longitude and latitude to google LatLng but I got undefined in console

name          : string ;
  address       : string ;
  clinc         : any    ;
  rate          : any = 0;
  image         : any    ;
  hosp          : any    ;
  qualifications: any    ;
  services      : any    ;
  phone         : any    ;
  spec           = []    ;
  icInsu        : any    ;
  isCFav        : boolean;
  ClinicData    : any    ;
  userRate      : number ;
  id            : string ;
  lattitude : number ;
  longitude : number  ;
  user_id = JSON.parse(localStorage.getItem('loginData')).id;



  constructor(private launchNavigator: LaunchNavigator,
    private             toastCtrl       : ToastController,
    public              navCtrl        : NavController,public AlertController: AlertController,
    private             callNumber     : CallNumber,public Http: Http,public StatusBar: StatusBar,
    private             GoogleMaps     : GoogleMaps,
    public              navParams      : NavParams, public Platform: Platform) {

    if (Platform.is('android')) {
      StatusBar.overlaysWebView(false);
      StatusBar.backgroundColorByHexString('#000000');
    }

     StatusBar.styleDefault();
     StatusBar.styleBlackTranslucent;

     let id : string = this.navParams.get('id');


         if (this.Platform.isRTL) {
           this.Http.post( APIURl, { isEnglish : 2 , id : id ,user_id : this.user_id})
           .map(res => res.json())
           .subscribe(data => {
             this.ClinicData = data[0];
             console.log(this.ClinicData);
             this.name = this.ClinicData.name;
             this.address = this.ClinicData.address + this.ClinicData.area_name + this.ClinicData.city_name;

             this.clinc = this.ClinicData.clinic_name;
             this.hosp = this.ClinicData.hosp_name;

             this.services = this.ClinicData.services;
             this.phone = this.ClinicData.personal_number;

             this.image = this.ClinicData.image;
             this.isCFav = this.ClinicData.is_fav;
             this.userRate = this.ClinicData.user_stars;

             this.spec = this.ClinicData.spec.split(',')
             this.icInsu = this.ClinicData.ic_images.split(',')

             this.longitude = this.ClinicData.long
             this.lattitude = this.ClinicData.lat


             },
            err =>{
              console.log(err)
             })
       } else {
           this.Http.post(apiURl, { isEnglish : 1 , id :id ,user_id : this.user_id})
         .map(res => res.json())
         .subscribe(data => {
           this.ClinicData = data[0];
           console.log(this.ClinicData);
           this.name = this.ClinicData.name;
           this.address = this.ClinicData.address + this.ClinicData.area_name + this.ClinicData.city_name;

           this.clinc = this.ClinicData.clinic_name;
           this.hosp = this.ClinicData.hosp_name;

           this.services = this.ClinicData.services;
           this.phone = this.ClinicData.personal_number;

           this.image = this.ClinicData.image;
           this.isCFav = this.ClinicData.is_fav;
           this.userRate = this.ClinicData.user_stars;

           this.longitude =  this.ClinicData.long
           this.lattitude = this.ClinicData.lat

          this.spec = this.ClinicData.spec.split(',')
          //  this.icInsu = this.ClinicData.ic_images.split(',')


        },
        err => {
          console.log(err)
        })
      }
    }
    ionViewDidLoad() {
      this.loadMap();
    }

    loadMap() {
      let element: HTMLElement = document.getElementById('map');
      let map: GoogleMap = GoogleMaps.create(element);


      map.one(GoogleMapsEvent.MAP_READY).then(
        () => {
          console.log('map')
        }
      )
      // console.log(  'here' + this.lattitude , this.longitude )
      let ionic : LatLng = new LatLng( this.lattitude , this.longitude );

      let position: CameraPosition < any > = {
        target: ionic,
        zoom: 18,
        tilt: 30
      };
     map.moveCamera(position);
     let MarkerOptions: MarkerOptions = {
       position: ionic
     };

     map.addMarker(MarkerOptions).then((marker: Marker) => {
       marker.showInfoWindow();
     })

   }

#2

This code is a trainwreck. All the HTTP stuff should be moved into a service provider. That will make you return Observables from said provider, and that should help you resolve the race condition you currently have.