Ionic Getting location Latitude and Longtitude

Step 1: In home.html

<ion-header>
  <ion-navbar>
    <ion-title>
      Map Location
    </ion-title>
  </ion-navbar>
</ion-header>
<ion-content padding>
<div *ngIf="isActive">
 
My current location is: {{ coords.lat }}, {{ coords.lng }}</div>
</ion-content>

Step 2: Adding code in home.ts

mport { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';</code>
 
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public coords: any;
public isActive: boolean = false;
 
constructor(public navCtrl: NavController, public platform: Platform, private geolocation: Geolocation, private googleMaps: GoogleMaps) {
 
}
 
ionViewDidEnter() {
   this.geolocation.getCurrentPosition().then((resp) => {
      this.coords = {
        lat: resp.coords.latitude,
        lng: resp.coords.latitude
     };
     this.isActive = true;
  }).catch((error) => {
     console.log('Error getting location', error);
   });
 }
}