Timeout while searching for location - Angular 2
See original GitHub issueDescription 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.
Steps To Recreate
tns create geolocation --ng- replace the code in app.component.ts with the code above
tns livesync ios --emualtor --watchortns 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:
- Created 7 years ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey @burkeholland,
For the Android side you could check out:
Let me know how it goes.
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 > Locationmenu fixed the simulator. NowgetCurrentPositiondoes 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.