Ionic get current location


ionic 2 get current location works once we restart our android device, please help me to fix this issue.


Check on this tutorial, hope it helps. Native Google Maps and Geolocation ionic


Thank you, i tried it but couldn’t fix the problem. It shows lang & lat as ‘undefined’.


Could you share your code as it will help me or someone assist you.


Code :


     let location='lat '+res.coords.latitude+' lang '+res.coords.longitude;
    let toast = this.toastCtrl.create({
    message: location,
    duration: 3000



I just run your code and it works fine. I use this as a guide - Geolocation

My .ts file

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

  selector: 'page-login',
  templateUrl: 'login.html',
export class LoginPage {

    public navCtrl: NavController, 
    public navParams: NavParams, 
    public geolocation: Geolocation,
    public toastCtrl: ToastController) {
  ionViewDidLoad() {

    this.geolocation.getCurrentPosition().then((res) => {
      // resp.coords.latitude
      // resp.coords.longitude
      //let location= 'lat'+ res.coords.latitude +'lang'+ res.coords.longitude;
      let location='lat '+res.coords.latitude+' lang '+res.coords.longitude;
      let toast = this.toastCtrl.create({
        message: location,
        duration: 3000

    }).catch((error) => {
    console.log('Error getting location', error);

Install the Cordova and Ionic Native plugins:

$ ionic cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="To locate you"
$ npm install --save @ionic-native/geolocation


It’s working fine in windows platform. but it’s not working in android device after generating apk.


same problem with me not work on android device :frowning:


try with command - ionic cordova run android --prod


Its working for me thanks bro :slight_smile:


It is not working in live application as well as run app through android studio in android
In error giving blank.
“Error getting location ---- {}”, source: file:///android_asset/www/build/main.js (384)

Ionic v1 geoocation doesnt work

Please refer this coding its must work,but you can import plugins in geolocation,geocoder.Then import app.module.ts file,then where you want to use this coding copy and paste it.

//get location coding this file you can paste it.
import { NativeGeocoder, NativeGeocoderReverseResult, NativeGeocoderOptions } from ‘@ionic-native/native-geocoder’;

selector: ‘page-register’,
templateUrl: ‘register.html’,
export class RegisterPage {
//declare the variable
data:any = {};
public deviceInfo: deviceInterface = {};
loading: any;
public lat:number;
public lng:number;

//parameters are used to geolocation.
constructer(public nativeGeocoder: NativeGeocoder,public geolocation: Geolocation){
//Get a location
this.geolocation.getCurrentPosition({enableHighAccuracy: true}).then((resp) => { resp.coords.latitude;
this.lng= resp.coords.longitude;
}).catch((error) => {
console.log(‘Error getting location’, error);

//lat and lng conversion of original address.
let options: NativeGeocoderOptions = {
useLocale: false,
maxResults: 2
.then((result: NativeGeocoderReverseResult) =>{ result[1].subLocality +","+ result[1].locality +","+
result[1].subAdministrativeArea +","+ result[1].administrativeArea +"-"+
result[1].postalCode +","+result[1].countryName;
}).catch((error: any) => console.log(error));
its work correctly,please refer this coding,try it.