Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Timeout searching for location on Android (Nativescript 3.0.3) #62

Closed
clarenceh opened this issue Jun 6, 2017 · 44 comments
Closed

Timeout searching for location on Android (Nativescript 3.0.3) #62

clarenceh opened this issue Jun 6, 2017 · 44 comments
Assignees
Labels
Milestone

Comments

@clarenceh
Copy link

I saw issues reported on forum and this repository about issues on reading location on Android on NS3.0. I just want to report that it also not working on Nativescript Sample application.

Steps to reproduce:

The plugin runs fine on iOS.

Attached please found the screenshot for your reference.

Versions:
│ Component │ Current version │ Latest version │ Information │
│ nativescript │ 3.0.3 │ 3.0.3 │ Up to date │
│ tns-core-modules │ 3.0.1 │ 3.0.1 │ Up to date │
│ tns-android │ 3.0.1 │ 3.0.1 │ Up to date │
│ tns-ios │ 3.0.1 │ 3.0.1 │ Up to date │

Hope this can help and let me know if need any further information.

Regards
Clarence
ns-android-location-error

@OPADA-Eng
Copy link

same thing happening with me. any help ?

@OPADA-Eng
Copy link

I noticed that sometimes the internet connection type may cause this problem so try to change internet provider.

@tbozhikov
Copy link
Contributor

Hi @clarenceh, looking at the sceenshots I see that you are running the app on emulator. You might check the Location options/settings/controls of the emulator if you can "Send" location to the device like the Android emulator for Mac:
image
Do you guys get the same exception when running the app on a physical device?

@dvdbrk
Copy link

dvdbrk commented Jul 16, 2017

Got the same problem. I don't think it has anything to do with emulator tho 😕

@marcel-braun
Copy link

I get the same error. iOS is working but Android unfortunately not.

@jaredjohnson59
Copy link

Has anybody found a solution for this issue on Android? I am still getting the following "JS: Error: Timeout while searching for location!"

@bufke
Copy link

bufke commented Jul 26, 2017

Running the Send location command as described in the Android emulator makes it work for me - of course that is a workaround and generally unpleasant.

@clarenceh
Copy link
Author

@tbozhikov Sorry for my late reply. Yes I can send location to the emulator. I opened Google Map, and then in emulator's location setting, change the value for latitude and longitude, and the location on the map was updated successfully. Have you had a chance to check out the NS Angular examples and test it out as I mentioned in my message? I believe you will be able to re-produce this. Many thanks, Clarence

@jeremypele
Copy link

jeremypele commented Aug 4, 2017

Got the same issue here. Tested on many emulators and many real devices.
Last one is on Android 7.0, wifi - network - gps enabled. Timeout on location request almost anytime.

Using version 3.0 of the plugin

As for my dependencies:

┌──────────────────┬─────────────────┬────────────────┬─────────────┐
│ Component        │ Current version │ Latest version │ Information │
│ nativescript     │ 3.1.3           │ 3.1.3          │ Up to date  │
│ tns-core-modules │ 3.1.0           │ 3.1.0          │ Up to date  │
│ tns-android      │ 3.1.1           │ 3.1.1          │ Up to date  │
│ tns-ios          │ 3.1.0           │ 3.1.0          │ Up to date  │
└──────────────────┴─────────────────┴────────────────┴─────────────┘

@lecaobaophuc0912
Copy link

lecaobaophuc0912 commented Aug 5, 2017

Hi , i have error same thing, i fix with open Location( or GPS ) of device choose Location Mode is a Hight accuracy. A reason is your device auto turn on Battery saving move or Device only mode. it is slow in get location from GPS. that plugin working with android and ios with me, i think it not a prolem.
Hope this will help...

@jeremypele
Copy link

jeremypele commented Aug 7, 2017

@LeCaoPhuc Regarding the different tests I've done this weekend: on a real device it works well when data is active. If gps + wifi are active then it's not working well - even if accuracy is set to the highest on device settings

@lecaobaophuc0912
Copy link

lecaobaophuc0912 commented Aug 7, 2017

@jeremypele your mean is in real device, if you use data (3g,4g) and turn on gps then you always get location. but if use wifi to connect internet, location will slow and time out if accuracy not in highest .
If problem as you talk , i don't know reason because with me, event if Device only mode in GPS all work fine.

@moayadnajd
Copy link

same thing happening with me. any help ?

@F481
Copy link

F481 commented Aug 9, 2017

Same problem for me on real Galaxy S7 with Android 7.

@PerryRylance
Copy link

Hi have this problem on my Samsung A5

@F481
Copy link

F481 commented Aug 19, 2017

Hi guys, please try to set the "desiredAccuracy" option to "Accuracy.high" (see https://docs.nativescript.org/hardware/location#getcurrentlocation).
That solved the problem for me 👍

@OPADA-Eng
Copy link

OPADA-Eng commented Aug 19, 2017 via email

@TinoN
Copy link

TinoN commented Aug 29, 2017

nativescript-geolocation plugin version: 3.0.1

I had the same problem as described. Apparently first you have to call .watchLocation(); This seems to trigger the retrieval of the current GPS data.
I am using my device (XiaoMi 5S) directly without emulator.

So here is what I did (I practically called .getCurrentLocation(...); and .clearWatch(watchId); after .watchLocation();:

function buttonGetLocationTap(args) {
    if (!geolocation.isEnabled()) {
        geolocation.enableLocationRequest();
    }

    watchId = geolocation.watchLocation();

    var location = geolocation.getCurrentLocation({desiredAccuracy: 3, updateDistance: 5, timeout: 20000})
    .then(function(loc) {
        if (loc) {
            console.log("Latitude " + loc.latitude);
            console.log("Longitude " + loc.longitude);
            console.log("Altitude " + loc.altitude);
            console.log("Horizontal Accuracy " + loc.horizontalAccuracy);
            console.log("Vertical Accuracy " + loc.verticalAccuracy);
            console.log("Speed " + loc.speed);
            console.log("Direction " + loc.direction);
            console.log("Timestamp " + loc.timestamp);

            geolocation.clearWatch(watchId);
        }
    }, function(e){
        console.log("Error: " + e.message);
        geolocation.clearWatch(watchId);
    });
}
exports.buttonGetLocationTap = buttonGetLocationTap;

Hope it helps.
Regards!

@CoderTonyB
Copy link

CoderTonyB commented Aug 30, 2017

Per TinoN's suggestion, I added this before my call to getCurrentLocation and it works. Note, this is the typescript version:
let watchId = watchLocation(x => this.lastLocation = x, x => console.log(x), null);

correction - this is not working reliably. The only thing that works reliably is clicking the send button in the emulator controls as per tbozhikov's suggestion above.

@TinoN
Copy link

TinoN commented Aug 30, 2017

@toeknee581 I checked it again with my phone. It worked in the office where I have WiFi. As soon as I left the building and had only access to mobile network it didn't work. On my mobile phone I switched the phone location settings from "High accuracy" to "Device only" to force GPS only usage. The data was then most of the time retrieved reliably (sometimes the phone GPS couldn't be accessed...). But when I came back to my office I switched back the phone settings to "High accuracy" to make sure that GPS, WiFi or Mobile can be used to determine location. From then on it stopped working in the office.

So I agree with you, it is not working reliably and I also can't reproduce when it is working and when not...

@angeltsvetkov angeltsvetkov added this to the vFuture milestone Sep 1, 2017
@TinoN
Copy link

TinoN commented Sep 1, 2017

Nativescript version: 3.1.3
Android verion: 6.0.1 (XiaoMi 5S)

Hello,
I still was not able to get it to work. And I also couldn't figure out, what the actual problem in the nativescript-geolocation code might be. (too many callbacks for me :))
Therefore based on the nativescript-geolocation code I tried figuring out how to actually trigger the GeoLocation update for my android phone. This way I was able to control the location update whenever I wanted. The phone reacted immediately and always gave me the expected results, no more timeouts.
You can see the result here.
You can see the usage of the Android API directly and how to trigger requestSingleUpdate(...), requestLocationUpdates(...) and removeUpdates(...).
Any comments, suggestions and/or questions are very welcome.
Regards!

@radeva radeva modified the milestones: 3.3, vFuture Sep 13, 2017
@mohammadrafigh
Copy link

@TinoN1e unfortunately your code doesn't work on my phone Android 5.1 (I changed your permission function to fit my API level).

to clarify more about this issue: actually everything works fine with nativescript-geolocation in emulator when "Send" button inside emulator pressed. but I tried the same code on real devices with different android versions but no result with COARSE or FINE, watch or single update... I traced nativescript-geolocation completely and nothing is wrong here. also I wrote an example app like @TinoN1e to work directly with android APIs but it doesn't work neither. so I think maybe something is wrong with nativescript code or android runtime. I didn't try Fused Location API on android. maybe this works rather than using location manager. I will try it tomorrow and share the results.

@TheOnlyMatt
Copy link

I finally succeeded to get the GPS work
I took Tino's code and made some improvements on it, because it was not locating me correctly.

I also noticed, that if you move a little bit in the offices, the location change event can be triggered, which will then give you the correct geolocation data.

@DimitarTachev
Copy link
Contributor

As there are a lot of issues with the Android Location Manager and it's not the recommended approach for getting a location on Android, we fully replaced the Android implementation with the Google Play Location Service one (used by Google Maps).

The change is currently on a pull request and we are still testing some edge cases. However, you could check if your issues are resolved using the tachev/location-manager-to-google-play-services branch.

@mohammadrafigh
Copy link

@DimitarTachev I tried your branch and still I get timeout.

@mohammadrafigh
Copy link

today I tested the same app on iOS 11 and I get timeout there too. so the problem is not related to Android side. maybe a Nativescript runtime issue?

@zbranzov
Copy link
Contributor

zbranzov commented Oct 9, 2017

@DimitarTachev @mohammadrafigh Using your branch and the corresponding demo on Lenovo A6010 Android 5.0.2 I was able to get location using gps service.

@zbranzov
Copy link
Contributor

zbranzov commented Oct 9, 2017

@mohammadrafigh Regarding iOS, be sure you have wifi on. This seems to fix it on my side but I guess this should be a separate discussion for another issue related to iOS.

@DimitarTachev
Copy link
Contributor

We closed the issues as the Android implementation is fully replaced by a new one and we are not able to reproduce the timeouts anymore.

You could take a look at the 4.0.0 release notes here.

@mohammadrafigh
Copy link

ah nice. I can now confirm that the issue is fixed on Android. I don't know why in previous try I got timeout. but now everything works fine. thanks @DimitarTachev .

@guestisp
Copy link

I'm also getting this.
Tried everything, including the watchLocation trick, but it doesn't solve the issue.
Any idea?

@guestisp
Copy link

Bump. I get the same issue even in latest version 4.2.1

@scottmcmu
Copy link

I am getting the same error with version 4.2.2. I also tried the watchLocation trick.

@tsonevn
Copy link

tsonevn commented Dec 19, 2017

Hi @guestisp, @scottmcmu,
Thank you for contacting us.
We reviewed your case, however, we were unable to recreate an issue with the getCurrentLocation method, while using the latest version of the plugin 4.2.2.
Regarding that, it would help if you could open a new issue, where you could provide the following info:

  • NativeScript CLI versions
  • tns-core-modules versions
  • tns-android versions
  • tns-ios versions
  • node versions
  • npm versions
  • sample project, which could be used for debugging
  • exact steps which you are using while building the project

This info will help us to recreate the issue and to verify if there is a real problem.
Thank you in advance for your cooperation.

@guestisp
Copy link

@tsonevn i've opened a new issue

@yuukiii
Copy link

yuukiii commented Mar 15, 2018

I had the same issue and solved it by changing to desiredAccuracy: Accuracy.high

@cnqiuxue
Copy link

cnqiuxue commented Jun 1, 2018

I have the same problem
JS: ERROR Error: Uncaught (in promise): Error: Timeout while searching for location!

@pitchinnate
Copy link

I figured out that if you follow the tutorial it is actually incorrect. At least now it currently says to use:

const Geolocation = require("nativescript-geolocation");
const Accuracy = require("tns-core-modules/ui/enums");
...
Geolocation.getCurrentLocation({
            desiredAccuracy: Accuracy.high,
            updateDistance: 0.1,
            timeout: 20000,
          })

However I realized that Accuracy should be imported as:

const { Accuracy } = require("tns-core-modules/ui/enums");

if you want to use it that way. Or if you don't change your import statement you can use: Accuracy.Accuracy.high on the desiredAccuracy.

@youtpout
Copy link

youtpout commented Mar 5, 2020

I have this error, i add timeout 0 for resolve the problem
Geolocation.getCurrentLocation({desiredAccuracy: Accuracy.high, timeout: 0 })

@jorfranb
Copy link

jorfranb commented May 28, 2020

@youtpout answer worked for me,
On android emulator the only configuration for geolocations actions (watch and get) is setting

{
desiredAccuracy:3
}

If you use anything else will throw an exception for timeout, putting timeout:0 works for another desiredAccuracy value,,,

@youtpout
Copy link

I try on real device

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

No branches or pull requests