Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

native geolocation deprecated on Android #430

Open
mica16 opened this issue Nov 11, 2014 · 14 comments
Open

native geolocation deprecated on Android #430

mica16 opened this issue Nov 11, 2014 · 14 comments

Comments

@mica16
Copy link
Contributor

mica16 commented Nov 11, 2014

I struggle to make the geolocation works on Android, using ngCordova and of course the org.apache.cordova.geolocation plugin.

I came across this Jira:
https://issues.apache.org/jira/browse/CB-5977

Is ngCordova aware of this deprecation?

What is the best way today to use geolocation on Android with ngCordova?
Indeed, it seems that, when the plugin is installed, Android always try to use the native way, that..isn't available any more.

Should I write an ugly pseudo-code like:
if(window.cordova && isAndroid()) { useTheBrowserImplementation()} elseif(window.cordova && isIos()) {useNgCordova())} ?

Thanks a lot,

Michael

@felquis
Copy link

felquis commented Nov 19, 2014

@mica16 what errors you are getting with ngCordova? Because ngCordova already use the Web API ref

I'll make some tests with geolocation.

@mica16
Copy link
Contributor Author

mica16 commented Nov 22, 2014

@felquis I tested on Samsung S5, geolocation works.
On a Samsung S4, I don't get Javascript errors...but I don't get any data. I did:

return $cordovaGeolocation.getCurrentPosition({
                    enableHighAccuracy: true
                }).then(function (position) {
                    alert(JSON.stringify(position));
                    return {
                        lat: position.coords.latitude,
                        lon: position.coords.longitude
                    };
                }, function (error) {
                    alert(JSON.stringify(error));
                    return $q.reject(error);
                });

No Javascript alert is displayed at all, meaning that ngCordova doesn't return a promise in this case...

Actually, when I don't set the "Position" option (to get the local position of the phone user) on the Samsung parameter section, I don't get any data..and no errors is displayed...
I expected some errors to appear, involved by the promise.
=> can't use the app if "Position" is not set.

@steefaan
Copy link

@mica16 Any updates on this? Unfortunately I can't test on Samsung Galaxy S4 but I tested it on Samsung Galaxy S3, Samsung Galaxy S5 and Galaxy Tab 4 and it works for all. The problem I have with Android 4.4 in general is that WiFi is not able to find the location. On my Samsung Galaxy S3 the WiFi geolocation works fine.

@mica16
Copy link
Contributor Author

mica16 commented Dec 16, 2014

Hi,

Actually, I noticed that when the property enableHighAccuracy is set to true, the phone has to enabled GeoPosition, otherwise the Geolocation by the browser is not used, explaining my post above.
I found it very frustrating for certain lambda users that aren't aware about their phone settings.

Personally, in the context of my app, I set enableHighAccuracy to false, in order to benefit from the browser solution, in case were the GPS wasn't enabled.

@steefaan
Copy link

You got the WiFi geolocation working with enableHighAccuracy to false? For me it doesn't work. If I try to find the geolocation with disabled GPS on Android 4.4 nothing happens and it runs into a timeout.

@mica16
Copy link
Contributor Author

mica16 commented Apr 2, 2015

I found a tricky bug:
Having this code:

$cordovaGeolocation.getCurrentPosition({
                    enableHighAccuracy: true,
                    timeout: 15000
                })

and in the Android phone settings about "Position", the radio button set on "GPS only",
It ALWAYS reachs the timeout !
All users argued me that my queries were too long (more than 15 seconds in this case), but when I tell them:
"Try to set the Position mode to 'High accuracy'", they say: wow now it's fast !

Question so: why is timeout reached even when 'enableHighAccuracy: true' when using GPS ONLY ?

Here's a related stackoverflow question I found on the subject but no answer..:

http://stackoverflow.com/questions/27835425/html5-geolocation-not-working-with-gps-only-location-service-mode-on-android

And here's mine I asked:

http://stackoverflow.com/questions/29411697/timeout-about-geolocation-always-reached-when-position-mode-is-set-to-device-on

@sean-hill
Copy link

I'm having this exact same issue, any updates to this?

@mikeon
Copy link

mikeon commented May 8, 2015

I also, didn't find solution for that issue.

@Kukiwon
Copy link

Kukiwon commented Jul 9, 2015

+1 seeing the same issues on Galaxy S3 mini running Android 4.4.4

@mikeon
Copy link

mikeon commented Jul 9, 2015

@Kukiwon Did you try to install Crosswalk? Because this is remedy. Also you can create function with setinterval, at first run it will fail but next one will execute properly.

@Kukiwon
Copy link

Kukiwon commented Jul 9, 2015

@mikeon yes i'm using crosswalk. I'll try using an interval for getting a location and will keep you posted.

@Kukiwon
Copy link

Kukiwon commented Jul 10, 2015

@mikeon your proposed solution using an interval did not work for me. Eventually we reinstalled Android on the phone and now it works. Looks like it was an issue with the device. Thanks again!

@askannan
Copy link

same issue as mica16... Is there a way out, or is there some other plugin that I can use?

@MikhailRoot
Copy link

I've tried cordova-plugin-geolocation with ngCordova but it always returned me Timeout error, meaning it can't get device's position in my even 5 minutes set timeout, so the final solution for Android 5.1 at least:
i've added permissions to AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.NETWORK_ACCESS" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

it wasn't working without ACCESS_WIFI_STATE permission. Now it works even without a sim card, with wifi connected and location enabled.
In case someone will find it helpfull.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants