question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout while searching for location - Angular 2

See original GitHub issue

Description Of The Issue

When requesting a users location after a successful location services request, the getCurrentLocation method times out.

import {Component, OnInit} from "@angular/core";
var geolocation = require("nativescript-geolocation");

@Component({
    selector: "my-app",
    templateUrl: "app.component.html",
})
export class AppComponent implements OnInit {
    status:string = "Location services not enabled";

    ngOnInit() {
        if (!geolocation.isEnabled()) {
           geolocation.enableLocationRequest().then(() => {
                this.getLocation();
            });
        }
        else {
            this.getLocation();
        }
    }

    getLocation() {
       // this method times out when called from the enableLocationRequest promise
        geolocation.getCurrentLocation({ timeout: 20000 }).then((location) => {
            this.status = `Latitide: ${location.latitude}, Latitude: ${location.longitude}`;
        });
    }
}

Expected Result

The application should request access to the user’s location and then display their latitude and longitude.

Actual Results

The getCurrentLocation method times out.

geolocation-timeout-log.txt

Steps To Recreate

  1. tns create geolocation --ng
  2. replace the code in app.component.ts with the code above
  3. tns livesync ios --emualtor --watch or tns livesync android --watch (Android Studio Emulator)

Environment Configuration

  • NativeScript CLI 2.2.1
  • Node 5.4.0
  • iOS Simulator version 9.3
  • Android API version 22 Emulator

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
vchimevcommented, Aug 25, 2016

Hey @burkeholland,

For the Android side you could check out:

  1. The emulator should use the Google APIs System Image; here is a reference to the Android SDK Manager.
  2. In the Settings menu, the Location option should be turned ON.

Let me know how it goes.

0reactions
toddanglincommented, Dec 5, 2016

I ran in to this same challenge with the iOS Simulator and geolocation timeouts.

Burke’s solution worked for me, too, even though I had not set a custom location. I was using the standard/default “Apple” location. Simply changing this location to “None” and then back to “Apple” in the Debug > Location menu fixed the simulator. Now getCurrentPosition does not timeout.

It appears there is indeed an odd behavior in the iOS Simulator that requires you to change the Location value at least once to set it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Checking the timeout error on the port with Angular 2 and rjxs
I want to check if the request is timeout when I send a request to the port. I just want to print an...
Read more >
Angular 2 & Protractor Timeout: Here's How to Fix It
If testing your Angular 2 application with Protractor fails with a timeout, your asynchronous operations might run in the wrong zone.
Read more >
tick - Angular
The following example includes a nested timeout (new macroTask), and the tickOptions parameter is allowed to default. In this case, ...
Read more >
setTimeout() - Web APIs - MDN Web Docs
This value can be passed to clearTimeout() to cancel the timeout. ... While the first function is waiting to execute, the second function...
Read more >
How to Implement Idle Timeout in Angular | by Bhargav Bachina
This is the time that the user doesn't do anything on the app or away from the computer. It is typical for high-risk...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found