Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geolocation not working #1067

Closed
yogeshwar607 opened this issue Feb 13, 2017 · 32 comments
Closed

Geolocation not working #1067

yogeshwar607 opened this issue Feb 13, 2017 · 32 comments

Comments

@yogeshwar607
Copy link

yogeshwar607 commented Feb 13, 2017

Its not going in .then nor in .catch for android.
Working fine in browser.
Was working fine in previous ionic versions.

Geolocation.getCurrentPosition().then((resp) => { console.log("position", resp) }).catch((error) => { console.log('Error getting location', error); });

config.xml -
<plugin name="cordova-plugin-geolocation" spec="~2.4.1" />

package.json

"ionic-native": "^2.2.11",

system information:
Cordova CLI: 6.5.0
Ionic Framework Version: 2.0.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.0
ios-deploy version: 1.9.0
ios-sim version: 5.0.11
OS: macOS Sierra
Node Version: v7.4.0
Xcode version: Xcode 8.2.1 Build version 8C1002

Android device version 6.0.1
Note: permission is granted to app

@battika
Copy link

battika commented Feb 13, 2017

Try specifying a timeout and see what happens:

Geolocation.getCurrentPosition({timeout:15000}).then((resp).....

@yogeshwar607
Copy link
Author

getting error :
Position Error {code: 3, message: "Timeout expired"}

No luck

@stormwin
Copy link
Contributor

This plugin have a problem. It cannot detect whether gps or location service options are disabled. So, first of all, check if 'Access to my location' option is enabled in your phone. Then activate GPS option, and finally try with your app

@ihadeed ihadeed closed this as completed Mar 2, 2017
@sunil237216
Copy link

@ihadeed why this issue is being closed without solution

@blogui91
Copy link

In my case, my problem was my cell phone was in airplane mode. :/

@acastry
Copy link

acastry commented Nov 14, 2017

Is there a final fix to this issue.
It's a major problem that needs to be adressed fastly.
Not beeing able to do location on mobile, for a mobile programming language is a rare problem.
Cordialement,

@mlynch
Copy link
Collaborator

mlynch commented Nov 14, 2017

The issue is closed because it seems like the error is not with the plugin but with something else, like airplane mode being on, etc.

Happy to open it up again if someone can provide more tangible reproduction of a bug in the actual plugin or Ionic Native's wrapper of it.

@mora260
Copy link

mora260 commented Nov 17, 2017

Not working for me on iOS device. Always get an error. After installing the plugin, no specification is made in Info.plist of the app requesting to use location. Maybe the error is there...

@andygup
Copy link

andygup commented Nov 19, 2017

Happy to open it up again if someone can provide more tangible reproduction of a bug in the actual plugin or Ionic Native's wrapper of it.

@mlynch Please reopen: by ruling out all other potential issues, my testing seems to indicate that Ionic is the source of this bug. I can share more detailed results if requested.

My conclusion: WebView is not the issue, no problems with native SDK or airplane mode. Geolocation works fine in stand-alone Cordova, and it also works when using a specialized Cordova GPS plugin.

Note: Using airplane mode does not disable Geolocation except when using a non-cellular enabled, WiFi-only tablets. Using airplane mode will actually force Geolocation to use GPS on all cellular-enabled devices.

Cross-reference: andygup/ionic2-esri-map#8

@ihadeed
Copy link
Collaborator

ihadeed commented Nov 19, 2017

Here's a project using @ionic-native/geolocation with no issues. Feel free to fork the repo and reproduce any issues you're having, and I'll be happy to take a look.

https://github.com/ihadeed/ionic-native-geolocation-test

@andygup
Copy link

andygup commented Nov 21, 2017

@ihadeed Thanks for clarifying and providing the sample, yes the Ionic Geolocation plugin pattern in that repo does work for me.

Verified on Ionic 3.18.0/Cordova 7.1.0 compiled with Android 6.3.0 running on an Nexus 6P at Android 8.0.0.


However there was another issue we noted. We have customers initializing navigator.geolocation directly inside OnInit.

Problem: This pattern broke at Angular 5:

    ngOnInit(){
        // This pattern is now broken! :-(
        navigator.geolocation.watchPosition( . . . );
    }

Resolution: We have been able to resolve this lifecycle issue by making sure to use Ionic's platform.ready(). This may also resolve similar issues that other people were seeing.

Here's a psuedo-example:

  async  startLocation(){
    await this.platform.ready();
    navigator.geolocation.getCurrentPosition(function(result){ . . . }
  }

  ngOnInit(){
    . . .
    this.startLocation();
    . . . 
  }

STATUS: Resolved

@hayat12
Copy link

hayat12 commented Dec 28, 2017

i think this happened because of timing problem if anyone have timing problem maybe try this its perfectly working

` ngOnInit(){
this.MyLocation();
}

MyLocation(){
this.platform.ready().then(()=>{
let options = {timeout: 10000, enableHighAccuracy: true, maximumAge: 3600};
this.geolocation.getCurrentPosition(options).then((resp) => {
alert(JSON.stringify(resp));
}).catch((error) => {
alert(JSON.stringify(error));
});
}).catch((er)=>{
alert(JSON.stringify((er)));
});
}`

@mlynch
Copy link
Collaborator

mlynch commented Jan 6, 2018

Leaving this link here in case it helps others test Geolocation on Android: https://blog.ionicframework.com/testing-geolocation-on-android/

@technbuzz
Copy link

Even if I provide timeout neither then nor catch works

@mrafayfarooq
Copy link

I am having the same issue. Is there any updated solution for this?

@hayat12
Copy link

hayat12 commented Jan 11, 2018 via email

@mrafayfarooq
Copy link

The code is neither going to then block nor catch any error and just exit. Tried the repo of ihadeed and also the example is given by you and same result. Your example is throwing a timeout. Trying on emulator and running ihadeed repo.

@hayat12
Copy link

hayat12 commented Jan 12, 2018 via email

@mrafayfarooq
Copy link

I think timeout:30000 make it work. Previously it was not working when set to 10000.

@diogoslap
Copy link

diogoslap commented Feb 7, 2018

Hello guys, well...nothing is working for me... I tried the codes here...but keep returning Error or empty values. I turn on my gps, enable permissions...I tried to run on emulator...but still not working...I cloned the project from @ihadeed but didn't work. Tested on Xperia X Compact(7.1.1) and Samsung S5 (6.0)
That's my info
ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@ionic/app-scripts : 3.1.2
Cordova Platforms  : android 6.4.0
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 26.1.1

Any ideas??

@jeffreyrajanofficial
Copy link

jeffreyrajanofficial commented Feb 7, 2018

Same here.. The geolocation plugin is not working in Android O. Can anyone help me on this?

@hayat12
Copy link

hayat12 commented Feb 7, 2018 via email

@kieranbehn
Copy link

I am having the same issue using a Nexus 7 with Aeroplane mode enabled. The code below does not log anything to the console, and does not timeout.

this.geolocation.getCurrentPosition({timeout: 30000}).then((resp) => {
  console.log(resp);
}, (error) => {
  console.log(error);
}).catch((err) => {
  console.log(err);
});

@diogoslap
Copy link

diogoslap commented Feb 7, 2018

Guys, I tried to compile in another computer...and believe...it works! But only with the GPS turn on. I didn't change the code of @ihadeed. Just compile...See my infos here...it's a downgrade...

ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0

global packages:

cordova (Cordova CLI) : 7.0.1 

local packages:

ionic/app-scripts : 3.1.2
Cordova Platforms  : android 6.4.0
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 26.0.2

I believe it's something about the SDK version or Gradle... The gradle here is 4.1.
I will try later in my computer to do a downgrade and test again to see if the results are the same.

@technbuzz
Copy link

technbuzz commented Feb 10, 2018

I had difference solution, more of a general understanding of Geo Location. I wrote about it because I figured it out after a lot of struggle and research. Hope it helps.

@franzisk
Copy link

Hi, I have followed the link bellow to test on the device:
https://github.com/andygup/ionic2-esri-map

Checking on Android Studio Logcat I see:
Caught security exception while registering for location updates from the system. The application does not have sufficient geolocation permissions.

My AndroidManifest.xml is:

<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.ionic.starter" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
</manifest>

What other permission should be there?

@mashalzia
Copy link

@ihadeed - clonned your project, not working in android.

@rroa
Copy link

rroa commented Apr 22, 2018

I'm having similar issues. I've been debugging it for a while now and it's related to the fact that the application is running locally on the HTTP protocol instead of HTTPS. https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only

When deployed directly to the device it works just fine. When using emulators without the live and console flags, it works fine as well.

@Sh1n1x
Copy link

Sh1n1x commented May 8, 2018

I've the same problem, but... something's geolocation is working on Android.... When i try with the example is the same, something's not working and something's working. (i'm not in airplane mode).

(if i open Gmaps or other, GPS work fine, is not my phone the problem).

This problem is only on Android, with iOS and browser work perfectly

@manish29ify
Copy link

Try Background Geolocation instead of Geolocation it solved my problem

@1pluszone
Copy link

There is just something wrong somewhere with android and getting location.. My geolocation code works well with 'ionic serve'. But just getting error callback (timeout error) on android. I increased the timeout to 30 seconds, still the same error... Probably it has to do with versions.

@mlynch
Copy link
Collaborator

mlynch commented May 21, 2018

Hi all. This is a bug in Cordova. The Geolocation implementation for Android relies on the web view geolocation implementation, but that behavior with Android is broken. The only solution here is for Cordova to add back the native geolocation implementation. We have a discussion going internally about how we might do that, but it also seems that Cordova is not interested in bringing that code back.

However, Capacitor, our new native bridge to replace Cordova, does use the native implementation. Once Capacitor is integrated into Ionic Native, this issue will be resolved.

Until then, this plugin will also have that bug. Closing until we have more information.

Repository owner locked as too heated and limited conversation to collaborators May 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests