import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import {Myservice} from '../../providers/myservice';


@IonicPage()
@Component({
  selector: 'page-location',
  templateUrl: 'location.html',
})
export class LocationPage {
	lat_lng:any;
	garages:any;
  constructor(public navCtrl: NavController, public navParams: NavParams, public storage: Storage, private myservice: Myservice) {
	  console.log("Fgfg");
			this.storage.get('lat_lng').then((lat_lng) => {
			console.log("instorage"+lat_lng);
			if(lat_lng){
				this.lat_lng=lat_lng;
				this.get_garages();
			}
		})
		//this.lat_lng ={'lat':'9.9312328','lon':'76.2673041'}
		
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad LocationPage');
  }

  shopdetail(id)
  {
 
	this.navCtrl.push('ShopdetailPage',{'garage_id' : id,'page' : 'location'});
	 
  }
  	doRefresh(refresher) {
		console.log('Begin async operation', refresher);

		setTimeout(() => {
			this.get_garages();
			console.log('Async operation has ended');
			refresher.complete();
		}, 2000);
	}
      get_garages(){
		//this.myservice.show_loader();
		this.myservice.load_post(this.lat_lng,'get_nearest_garages').subscribe(data => {
			//this.myservice.hide_loader();
			if(data.status == 'success'){
			 
				  this.garages = data.data;
				 
				 
			}
		});
	}

}
