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.

iOS getCurrentLocation returns nothing after a few seconds

See original GitHub issue

Please, provide the following version numbers that your issue occurs with:

"nativescript": {
    "id": "org.nativescript.application",
    "tns-android": {
      "version": "5.0.0-rc-2018-10-18-172901-01"
    },
    "tns-ios": {
      "version": "5.0.0"
    }
  },
  "dependencies": {
    "http": "0.0.0",
    "https": "^1.0.0",
    "nativescript-geolocation": "^4.3.1",
    "nativescript-localstorage": "^2.0.0",
    "nativescript-mapbox": "^4.4.0",
    "nativescript-theme-core": "^1.0.4",
    "nativescript-ui-sidedrawer": "^4.3.0",
    "nativescript-vue": "^2.0.0",
    "querystring": "^0.2.0",
    "request": "^2.88.0",
    "tns-core-modules": "^4.2.0",
    "vuex": "^3.0.1"
  },

What I am trying to do is to send geolocation information via https to a server. This info will be sent when the app is pushed in the background. I’ve followed the sample app https://github.com/NativeScript/sample-ios-background-execution for implementing a background delegate.

However, after running the command tns run ios --bundle --emulator, and press the home button to push the app into the background, the getCurrentLocation function returns nothing after a few seconds.

Here’s an example of my console:

CONSOLE LOG file:///app/bundle.js:1685:20: 'Enter background'
...
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1359:16: '{"latitude":37.785834,"longitude":-122.406417,"altitude":0,"horizontalAccuracy":5,"verticalAccuracy":-1,"speed":-1,"direction":-1,"timestamp":"2018-11-27T18:55:52.234Z","ios":{}}'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1359:16: '{"latitude":37.785834,"longitude":-122.406417,"altitude":0,"horizontalAccuracy":5,"verticalAccuracy":-1,"speed":-1,"direction":-1,"timestamp":"2018-11-27T18:55:52.234Z","ios":{}}'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1359:16: '{"latitude":37.785834,"longitude":-122.406417,"altitude":0,"horizontalAccuracy":5,"verticalAccuracy":-1,"speed":-1,"direction":-1,"timestamp":"2018-11-27T18:55:52.249Z","ios":{}}'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1359:16: '{"latitude":37.785834,"longitude":-122.406417,"altitude":0,"horizontalAccuracy":5,"verticalAccuracy":-1,"speed":-1,"direction":-1,"timestamp":"2018-11-27T18:55:58.255Z","ios":{}}'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'
CONSOLE LOG file:///app/bundle.js:1712:20: 'Printing geolocation:'

I don’t know what could be causing this? Could it be due to the geolocation module calling a native API, which is returning nothing?

Update I included a check to see if the app has permission (Ie geolocation.isEnabled()), and it always returns true, I then call getCurrentLocation. Same result.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RaisinBread42commented, Feb 23, 2019

Any progress with this issue @zbranzov ?

1reaction
linicommented, Nov 28, 2018

Do you have the iosAllowsBackgroundLocationUpdates option set to true in the .watchLocation() call options?

If possible, provide a sample app (https://play.nativescript.org/ works great for this) so we can review the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ios - Objective C locationManager cannot get current location ...
Please try to call startUpdatingLocation after requestAlwaysAuthorization. and use below didUpdateLocations delegate methods.
Read more >
Geolocation - .NET MAUI - Microsoft Learn
GetLocationAsync can return null in some scenarios. This indicates that the underlying platform is unable to obtain the current location.
Read more >
nativescript-geolocation
In situation of poor or no GPS signal, but available Wi-Fi it will take 10 sec to return location. watchLocation(successCallback: successCallbackType, ...
Read more >
Ionic 5 Complete guide on Geolocation, permission and auto ...
If you create Native apps in iOS, you code in Obj-C/Swift. ... ionic start IonicGeo blank --type=react --capacitor ... getCurrentPosition; watchPosition.
Read more >
How To Get a User's Location with the Geolocator Plugin in ...
A simple guide on how to use the Geolocator plugin in Flutter to get the ... Starting with iOS and the Info.plist ,...
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