geoloc PositionError not correct when switching it OFF after app has been launched

  • 1
  • Problem
  • Updated 4 years ago
I would like to find a way to detect mobile geolocation switch when an app is already launched ? example : geoloc if OFF , I launch my APP , I get an error 1 = PositionError.PERMISSION_DENIED as expected . Then I turn my geoloc ON (still with my APP running) , I try to check again , and still get error 1 ... whicj is now wrong .
Contrary is OK : Geoloc is ON , and try to turn it OFF after my APP has been previously launched , then I receive an error 3 = PositionError.TIMEOUT which is correct .
Can you please answer for my first example ? and tell me how to solve this ?
best regards
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
You may want to read this:
GPS is Unreliable

Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
I've read your link , but unfortunatly , this is définitly not answering my question. Thanks anyway.
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
the problem occurs only when the GPS is OFF before app is launched. Then when you turn the GPS ON , the app doesn't see the change , even when you refresh . You have to kill the task (or close the app) and you start over. then GPS is detected correctly... I've read sometimes that it was a problem of html container that needs to be restarted . any other solutions ?
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sandro,
since this is your first "real" post and you are not familiar with GPS. I will try to keep this simple.

GPS is not reliable. This means just because you turn on a switch, it does not mean that GPS is going to work. There are a variety of reasons for this. The Link I gave you has a variety of reasons for this.

This means you MUST deduce the reason(s) why your GPS is failing. It could be a programmatic reason, or it could a reason stated on the list.

This also means, if this is your first app, you have a very difficult task. I would also say, if this is your first hybrid app - you should try sometime else, something simpler.

You have three options,
1) something simpler
2) work with a know working example.
3) Try to fix your App.

Let me know which you want to try.
Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
My app has been working for 3 years now. Gps and geolocation is working very good. you can download it on apple and google stores - search for MOBIWOOM CASHBACK and install one of the 2 you want .
The problem is not from GPS !
Let me ask my question in a different way :
Is there a way to check if geolocation is enabled or not in the customer's mobile and especially detect the change state in my APP ?
then if I can test that , I will have an answer at my above question?
Because now when I change the geolocation state when my app is running , turning it from OFF to ON , the geolocation error is still the same = PositionError.PERMISSION_DENIED. so I canno't detect the geolocation turned ON .
It's a matter of software problem , not GPS position or whatever is in your list.
So definitly my question is option 3 .
regards and thanks for your help
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sandro,
If your app has been on the App stores for three years, you should have stated so. I looked at your screen. You have not indicators to say you GPS is working or not. How did you deduce the GPS is not working?

FWIW: Alot has changed in three years. You are no longer allowed calls to remote servers without implementing the whitelist. This might be your issue.

Also, Is your target platform Android 6 or iOS 9? Neither is supported with *Phonegap Build* -- YET.

Is there a way to check if geolocation is enabled or not in the customer's mobile and especially detect the change state in my APP ?

No. If you do not get permission at install time, you will not get permission to install the app. So, if you app is installed, you will have permission to use the GPS.

If you get a PositionError.PERMISSION_DENIED, this is an error you must handle - by assuming the user gave you permission to use GPS at install time.

Okay, We are making head way. From what you are saying, I think your option will #2.

Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
whitelist is not the issue. I have added whitelist in my last dev . And when GPS is working so will see GPS Icon in the app . if no icon ... no GPS. When I debug, I can see error permission too. see Petra comment below ... this is the answer.
Photo of santhosh h

santhosh h

  • 4 Posts
  • 0 Reply Likes
### Android Quirks

If Geolocation service is turned off the `onError` callback is invoked after `timeout` interval (if specified).
If `timeout` parameter is not specified then no callback is called.

this is from readme(line 213). so now we only get timeout error rather then permission_denied error. If i'm wrong please correct me.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I have tested this in Android 4.1.x and 4.4 and found that the permission is checked at app launch only.

This should have alarmed you:
geoloc if OFF , I launch my APP , I get an error 1 = PositionError.PERMISSION_DENIED as expected . Then I turn my geoloc ON (still with my APP running) , I try to check again , and still get error 1 ... whicj is now wrong .
Contrary is OK : Geoloc is ON , and try to turn it OFF after my APP has been previously launched , then I receive an error 3 = PositionError.TIMEOUT which is correct .


Do you notice the two different error cases?

In scenario ON->OFF, the general permission is still there! Android will not pass a value, though (time out, not permission denied)
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
Hi Petra, that's unfortunatly what I was afraid.
I was thinking to make my app restart , in order to detect geoloc state change...
I don't see any other solution
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sandro,
ask the user to turn on the GPS. Users do NOT generally turn off the GPS when an app is running. In addition, because of NEW background requirements, restarting may be your only other option.

SEE: HEADS UP: Android 6.0 SDK-23 blocks background operations.

This is a decision you must make.

Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
I ask the user to turn the GPS on, but as the app is launched , when he turns it on , the app does not detect the new state , and the only solution is to ask the user to restart the app ... which is not very cool .
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sandro,
Like I said, your decision. FWIW you can file a bug report here. Note, you must create an account to file a bug report.

If you need help filing the report, let me know.

Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
the only solution I've found right now is a restart with location.reload();
this is the way to detect geolocation state change.
Then everything is working correctly .
waiting for a fix one of these days ...
thanks to all
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
waiting for a fix one of these days
What do you want fixed? It ain't broke, and if it was, it would be an Android problem, not a Phonegap problem.

I just pictured your perception of the situation as in:

A car driver reaches the point where the road is interrupted by an opened bridge. Instead of waiting for the bridge to be closed, he keeps on driving and, of course, tumbles off the road and into the water.
One day later he complains with the car manufacturer and demands a solution. The manufacturer replies: it is not a bug in the car. It is a feature by design...when the bridge is opened, cars are supposed to wait until the ship has passed and the bridge is closed again. It's the road manager who is responsible for the implementation of this feature, years ago.

Mumbles the car owner: OK. I'll use my brakes from now on, until this nasty bug gets fixed one of these days."
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sandro,
if you don't report this, it will never get a fix. Do you want to wait until someone else reports it?

@Petra,
I also see this as a minor item, but I think Sandro has a valid point. I'm willing to help get this bug report started.

Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
@JesseMonroy650,
I've looked at your report link ... too complicated for me ... I'm french and don't understand where to start . I ve signed up , but which desk ? I don't see build pnonegap ... sorry
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
Okay. Here is a pictorial tutorial. To be clear, you are reporting to Apache Cordova, the open-source project that feeds Phonegap. Let me know, if you need more help.

How to create a Cordova Bug Report on JIRA

Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
@JesseMonroy650,
I think it's OK , could you please check ?
https://issues.apache.org/jira/browse...
thank you
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Sandro,
Looks good. However, I expect they will want to ask a few questions.
But since you asked for a definite feature, I think the response will be good.

Thanks for fill out the form. I will follow it after you have answer any questions they have. Also, I left a comment, which means I will get an email (and you should also) after someone reviews the report.

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
It may be useful to explicitly state the PGB and plugin versions you are using.
After all, if you're using the latest cordova-plugin-geolocation@2.0.0 with PGB cli-5.2.0, you're most likely not getting a proper answer/result.
After all, cordova-plugin-geolocation@2.0.0 requires Cordova Android 5.x, which is not included in PGB cli-5.2.0
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
Good point. I'll make a note on that. -Jesse
Photo of Sandro Di Bernardi

Sandro Di Bernardi

  • 16 Posts
  • 0 Reply Likes
PGB is cli-5.2.0 yes
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
Yes. Currently PGB is cli-5.2.0.

Cordova Android 5.0.0, which Petra speaks of, was released in Nov of 2015, and is ONLY available for CLI.

The trail of releases is as such:

The latest Cordova/Phonegap Tool Release is 5.4.1. It is pinned to Cordova Android: ~4.1.0 (4.1.1), even though Cordova Android 5.0.0 was release a few weeks before the 5.4.1 Tool Release.

Sorry, if this is confusing, but the releases are not linear and not well organized.

Jesse
Photo of santhosh h

santhosh h

  • 4 Posts
  • 0 Reply Likes
### Android Quirks

If Geolocation service is turned off the `onError` callback is invoked after `timeout` interval (if specified).
If `timeout` parameter is not specified then no callback is called.

this is from readme(line 213). so now we only get timeout error rather then permission_denied error

their is this plugin this may help
https://www.npmjs.com/package/cordova...