Ionic-native: @ionic-native/geolocation.getCurrentPosition() is rejecting.

Created on 8 Aug 2017  路  4Comments  路  Source: ionic-team/ionic-native

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request

I have an Ionic 3.7.0 project. As I needed to implement a GPS feature, I installed cordova-plugin-geoloaction and @ionic-native/geolocation. I added it as on of my providers and included it to the page where I needed it.

geo-page.ts

if (this.platform.is('cordova')) {
      this.gps.getCurrentPosition().then(data => {
        this.location.lat = data.coords.latitude;
        this.location.lng = data.coords.longitude;

        console.log('[DEBUG] Location: ' + JSON.stringify(this.location));
      }, error => {
        console.log('[DEBUG] Promise Rejected. ' + JSON.stringify(error));
      }).catch(error => {
        console.log('[DEBUG] Promise Unfulfilled. ' + JSON.stringify(error));
      });

    [...]      

    }

This is what was output in the LogCat:

08-05 18:44:04.807 I/chromium(11230): [INFO:CONSOLE(121)] "[DEBUG] Promise Unfulfilled. {"__zone_symbol__currentTask":{"type":"microTask","state":"notScheduled","source":"Promise.then","zone":"angular","cancelFn":null,"runCount":0}}", source: file:///android_asset/www/build/1.js (121)

Here's the expanded JSON for ease...

{
   "__zone_symbol__currentTask":
      {
         "type":"microTask",
         "state":"notScheduled",
         "source":"Promise.then",
         "zone":"angular",
         "cancelFn":null,
         "runCount":0
      }
}

Ionic info

$ ionic info                                   

cli packages: (C:\ionic\node_modules)          

    @ionic/cli-plugin-cordova       : 1.6.2    
    @ionic/cli-plugin-ionic-angular : 1.4.1    
    @ionic/cli-utils                : 1.7.0    
    ionic (Ionic CLI)               : 3.7.0    

global packages:                               

    Cordova CLI : 7.0.1                        

local packages:                                

    @ionic/app-scripts : 2.1.3                 
    Cordova Platforms  : android 6.2.3         
    Ionic Framework    : ionic-angular 3.4.0   

System:                                        

    Android SDK Tools : 26.0.1                 
    Node              : v6.11.2                
    OS                : Windows 10             
    npm               : 3.10.10                

I have absolutely no idea what's going on. I followed the instructions and it just doesn't seem to be working.

package.json info:

{
    "name": "dat-name",
    "version": "dat-version",
    "author": "dat-author",
    "homepage": "http://knowyourmeme.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@ionic-native/core": "3.10.2",
        "@ionic-native/file": "^4.1.0",
        "@ionic-native/file-transfer": "^4.1.0",
        "@ionic-native/geolocation": "^4.1.0",
        "@ionic-native/google-maps": "^4.1.0",
        "@ionic-native/in-app-browser": "^4.0.0",
        "@ionic-native/network": "^3.13.1",
        "@ionic-native/splash-screen": "3.10.2",
        "@ionic-native/status-bar": "3.10.2",
        "@ionic-native/youtube-video-player": "^4.1.0",
        "@ionic/cli-utils": "^1.7.0",
        "@ionic/cloud-angular": "^0.12.0",
        "@ionic/storage": "^2.0.1",
        "cordova-android": "^6.2.3",
        "cordova-plugin-console": "1.0.5",
        "cordova-plugin-device": "1.1.4",
        "cordova-plugin-file": "~4.3.3",
        "cordova-plugin-file-transfer": "~1.6.3",
        "cordova-plugin-geolocation": "^2.4.3",
        "cordova-plugin-googlemaps": "https://github.com/mapsplugin/cordova-plugin-googlemaps#multiple_maps",
        "cordova-plugin-inappbrowser": "~1.7.1",
        "cordova-plugin-network-information": "~1.3.3",
        "cordova-plugin-splashscreen": "~4.0.1",
        "cordova-plugin-statusbar": "~2.2.2",
        "cordova-plugin-whitelist": "1.3.1",
        "cordova-plugin-youtube-video-player": "^1.0.6",
        "cordova-sqlite-storage": "~2.0.4",
        "ionic-angular": "3.4.0",
        "ionic-plugin-keyboard": "~2.2.1",
        "ionicons": "3.0.0",
        "phonegap-plugin-push": "^1.10.5",
        "rxjs": "5.4.0",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12",
        "com.hutchind.cordova.plugins.streamingmedia": "~0.1.4"
    },
    "devDependencies": {
        "@ionic/app-scripts": "^2.1.3",
        "@ionic/cli-plugin-cordova": "1.6.2",
        "@ionic/cli-plugin-ionic-angular": "1.4.1",
        "ionic": "3.7.0",
        "typescript": "2.3.3"
    },
    "description": "dat-app-description",
    "cordova": {
        "plugins": {
            "com.hutchind.cordova.plugins.streamingmedia": {},
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-file": {},
            "cordova-plugin-file-transfer": {},
            "cordova-plugin-googlemaps": {
                "API_KEY_FOR_ANDROID": "DIS_KEY"
            },
            "cordova-plugin-inappbrowser": {},
            "cordova-plugin-network-information": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "cordova-sqlite-storage": {},
            "ionic-plugin-keyboard": {},
            "phonegap-plugin-push": {
                "SENDER_ID": "DAT_KEY"
            },
            "cordova-plugin-geolocation": {},
            "cordova-plugin-youtube-video-player": {}
        },
        "platforms": [
            "android"
        ]
    }
}

All 4 comments

What do you get in the Chrome Dev logs? Is your phone GPS turned on?

@gianpaj It's been such a while. I even forgot to close this.

Heck I couldn't even remember what my solution was, but it's all OK now. My bad.

@christianwico, can you please share the solution??

@ailsoncgt I apologize for not sharing it before, but as I said back then:

Heck I couldn't even remember what my solution was...

That project was long completed, but I do still remember doing at least one _(or both)_ of these two things:

  • ~I made sure I wrapped the entire block in a platform.ready() block~
  • [EDIT: I strongly believe this is the solution] I also tried uninstalling the plugin and re-installing it.

~Again, I'm sorry this is all I could give right now, but anything beyond those two things I suggested I've completely forgot.~

EDIT REASON: I recall having issues with NPM back then after I tried to upgrade it from the LTS version. It was also during that time that I was working on the new GPS module.

Was this page helpful?
0 / 5 - 0 ratings