Get current location problem


I’m trying to use getCurrentPosition function from geolocation plugin to get my current location but it return error this is the code

this.geolocation.getCurrentPosition().then((position) => {

  let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

  let mapOptions = {
    center: latLng,
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  } = new google.maps.Map(this.mapElement.nativeElement, mapOptions);

  let marker = new google.maps.Marker({
    animation: google.maps.Animation.DROP,

}, (err) => {

Can anyone tell me why?

this.geolocation.getCurrentPosition().then((resp) => {
 // resp.coords.latitude
 // resp.coords.longitude


this.geolocation.getCurrentPosition().then((position) => {

let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

I do that??
but the map not appear


are you using google maps native


no, i’m using google maps sdk


No, i’m using google mas sdk


@Ben1nB1ack, now i’m using google maps native and it works fine but i want to get lat&long without display map. when I make #map display:none or height:0px. the plugin not woks


Ok, I’m confused, first you wanted to see the map and now you don’t :wink:

maybe if you told me what your end goal is.


I’m sorry about that, my end goal is in my app there is a registration page i want to display user location in it and if he/she wants to change it, when click button the map appear.
I hope that i could display the idea.


I would have both installled

google-maps-native which you have for display

there is a pluging called angular2-google-maps
it works with browser and on phone.
great video. on geolocation


guys i have set the ANDROID_HOME variable path when i echo the $ANDROID _HOME it shows correct path but when i am trying to build up my project ANDROID_HOME value is diffrent

bc@abc-HP-15-Notebook-PC:~$ echo $ANDROID_HOME

cordova build android
[11:44:35] lint finished in 3.24 s
Subproject Path: CordovaLib
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.


Checking the license for package Android SDK Platform 26 in /usr/lib/android-sdk/licenses
Warning: License for package Android SDK Platform 26 not accepted.

Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘android’.

You have not accepted the license agreements of the following SDK components:
[Android SDK Platform 26].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
Alternatively, to learn how to transfer the license agreements from one workstation to another, go to

  • Try:


It is not applicable to get location by google maps without display map??




but geolocation not works with me, it all the time return error.when i use ionic serve/ ionic lab it works fine but when i deploy the app in androd device it doesn’t work.


this is angular google maps, not geolocation


But this to be used needs lat&long which geolocation give them. doessn’t it?


Sorry, i got mySelf confused, LOL

may you should do

$ ionic cordova plugin rm cordova-plugin-geolocation 
$ npm uninstall --save @ionic-native/geolocation

$ npm rebuild

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

here is sample .ts

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

  selector: 'page-place-form',
  templateUrl: 'place-form.html',
export class PlaceForm {
  location: any;
  gmLocation: {lat: number, lng: number} = {lat: 0, lng: 0};

  constructor(private navCtrl: NavController, private geoloc : Geolocation) {

  onLocateUser() {
        (location) => {
          console.log('position gotten: long:',location.coords.longitude,' lat:',location.coords.latitude);
          this.location = location;
 = location.coords.latitude;
          this.gmLocation.lng = location.coords.longitude;
        (error) => {
          console.log('Error getting location', error);