1
votes

I have been testing the functionality of GPS on various android devices, I tried a simple snippet of code where I just do the following :

Location position = LocationManager.getLocationManager().getCurrentLocationSync();

and tried with timeout

Location position = LocationManager.getLocationManager().getCurrentLocationSync(20000);

and the device just got stuck with GPS signal on top

Searching for GPS

Device: Samsung SM-N900 [Samsung GALAXY Note 3] , Samsung Note 8 , and sometimes on Apple IPhone [IPhone 7]

-- on apple I think the issue could be reproduced if you call

Location position = LocationManager.getLocationManager().getCurrentLocationSync(20000);

more than once in a short period of time [ less than 1 minute or so ] and sometimes on apple it gives wrong readings if it takes too much time to get the result back from the gps


Update where I get exception when getting the current location from GPS on android with no wifi :

09-27 07:22:35.668: W/System.err(8801): java.io.IOException: cannot retrieve location try later
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.location.AndroidLocationPlayServiceManager.getCurrentLocation(AndroidLocationPlayServiceManager.java:74)
09-27 07:22:35.668: W/System.err(8801):     at c.a.iF(Unknown Source)
09-27 07:22:35.668: W/System.err(8801):     at b.a.a(Unknown Source)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.l.f$a.a(UIBuilder.java:2835)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.l.c.a(EventDispatcher.java:349)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.d.f(Button.java:570)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.d.g(Button.java:604)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.d.b(Button.java:708)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.u.b(Form.java:3259)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.l.f(Component.java:4288)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.q.a(Display.java:2065)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.q.j(Display.java:1043)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.q.i(Display.java:961)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.s.ai.run(RunnableWrapper.java:120)
09-27 07:22:35.668: W/System.err(8801):     at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
09-27 07:22:35.668: W/System.err(8801):     at java.lang.Thread.run(Thread.java:818)

appreciate the help

Regards,

1

1 Answers

0
votes

Location isn't always accurate. A GPS signal might be unreachable. We use hybrid location which combines the data from GPS and other sensors to give you an estimated location faster.

However, this value is constantly adjusting so the best/most accurate way to get a GPS signal is to use a listener. Notice that GPS is more accurate if you move.