import { Component, OnInit } from '@angular/core'; import { Geolocation } from '@ionic-native/geolocation/ngx'; import { ZBar, ZBarOptions } from '@ionic-native/zbar/ngx'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'], }) export class HomeComponent implements OnInit { zbarOptions:any; scannedResult:any; lat : any; longt : any; constructor(private zbar: ZBar, private geolocation: Geolocation) { this.zbarOptions = { flash: 'off', drawSight: false } console.log("your currnt location is"); this.geolocation.getCurrentPosition().then((resp) => { // resp.coords.latitude // resp.coords.longitude //console.log("Loc 2"); console.log(resp.coords.latitude); console.log(resp.coords.longitude); this.lat=resp.coords.latitude; this.longt=resp.coords.longitude; }).catch((error) => { console.log('Error getting location', error); }); this.scanCode(); } ngOnInit() {} onClick() { this.scanCode(); } scanCode(){ this.zbar.scan(this.zbarOptions) .then(result => { console.log(result); // Scanned code this.scannedResult = result; }) .catch(error => { alert(error); // Error message }); } }