Ionic geolocation

Hi to all, I’m trying to geolocate user in yours current position with ionic-native/geolocation plugin.
My snippet of code is:

this.geolocation.getCurrentPosition().then(res => {
      this.myLat = res.coords.latitude;
      this.myLon= res.coords.longitude;
      this.reverseGeocoding(this.myLat,this.myLon);
      console.log(this.start);
      this.map = new google.maps.Map(this.mapElement.nativeElement, {
        zoom: 7,
        center: {lat: this.myLat, lng: this.myLon}
      });

      this.directionsDisplay.setMap(this.map);
      this.addMarker(this.map);
    }).catch((error) => {
      console.log('Error getting location', error);
    });

On browser it works but on android devices not. What is the trouble? Thanks in advance

what error does it output??

On browser it works fine, on mobile device there is no error but map doesn’t load. this.geolocation.getCurrentPosition().then( res => {}) isn’t carry out

Using android device or ios??

Android device, I said that in first answer

If you want to create Google map app, I recommend you use @ionic-native/google-maps.
The plugin provides the same API for native Google Maps SDK for Android/iOS and Google Maps JavaScript API v3.

https://docs.google.com/presentation/d/e/2PACX-1vScoho1ensbR4qCI9AIuQN55BZVvK73pAjI7sumDvW3CrxxHnrmpXWUjx2-8CpFibqU1EjLKCRhuthJ/pub?start=false&loop=false&delayms=3000&slide=id.p

And it also provide original Geolocation API.

I had a similar issue recently - geolocation.getCurrentPosition() wasn’t returning anything.

A device restart got this working for me.

When I use ionic-native/google-maps plugin there is an error on my app:

Error: "Uncaught (in promise): TypeError: plugin is undefined
checkAvailability@http://localhost:8100/build/vendor.js:78342:9
LocationService.getMyLocation

but I’ve installed plugin with these two commands:

npm install @ionic-native/core @ionic-native/google-maps

ionic cordova plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="..." --variable API_KEY_FOR_IOS="..."

I guess you forget to wait platform.ready().

And also ionic serve does not work, because it does not load cordova.

Use ionic cordova run (browser/ios/android) instead.

Adding -l gives the live reload ability.

Now the error is: Error: "Uncaught (in promise): TypeError: google.maps.LocationService is undefined