0

I have no idea why I am getting these error. As far I have checked I don't think that the syntax are incorrect or something is missing. May be I am wrong. Please take a look at my code:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Geolocation } from '@ionic-native';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
coords:any;
accuracy:any;
error:any;

  constructor(public navCtrl: NavController) {

  }

watch(){
  Geolocation.getCurrentPosition().then(resp) => {
    this.coords= resp.coords.latitude+' '+resp.coords.longitude;
    this.accuracy= resp.coords.accuracy+' '+'meters';
  }).catch((error)=>{
    this.error='Error getting location'+error;
  })
}

}

//These are the error log in brief:

Typescript Error
';' expected.

Typescript Error
Declaration or statement expected.

Typescript Error
'try' expected.

2 Answers 2

1

Try this:

watch(){
  Geolocation.getCurrentPosition().then((resp) => {
  this.coords= resp.coords.latitude+' '+resp.coords.longitude;
  this.accuracy= resp.coords.accuracy+' '+'meters';
  }).catch((error)=>{
   this.error='Error getting location'+error;
  });
}

I guess you are missing a ";" after the catch and also a "(" after the then.

Sign up to request clarification or add additional context in comments.

1 Comment

Use a compatible IDE such as VSCode so you don't have to spot the error manually.
0
coords:any;
accuracy:any;
error:any;

coords could be changed to

coords: number

and then you would have typescript safety

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.