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.

Error: Cannot read property 'GoogleApiAvailability' of undefined

See original GitHub issue

From Documentation Example: https://docs.nativescript.org/hardware/location

Android platform

Plugin: nativescript-geolocation Latest version: 4.2.3

Sample Code:

var geolocation = require("nativescript-geolocation"); 
  var location = geolocation.getCurrentLocation({ desiredAccuracy: 3, updateDistance: 10, maximumAge: 20000, timeout: 20000 }).
        then(function (loc) {
            if (loc) {
                alert("Current location is: " + loc);
            }
        }, function (e) {
            alert("Error: " + e.message); console.log("Error: " + e.message);
        });


geolocation.getCurrentLocation() **Returns:**

Promise {[[PromiseStatus]]: “pending”, [[PromiseValue]]: undefined}proto: Promise[[PromiseStatus]]: “pending”[[PromiseValue]]: undefined

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
MeMartijncommented, Mar 7, 2018

(See TLDR at the bottom for some fixes to common problems)

So, after a little bit of fiddling, the format.replace error was caused by trying to console.log both the longitude and latitude in the same statement. Apparently (I’m not sure why), that will not work. The following code works if and only if I send a location through the extended controls on the Android emulator:

geolocation.isEnabled().then((available) => {
      if (available) {
        let location = geolocation.getCurrentLocation({desiredAccuracy: 3, updateDistance: 10, maximumAge: 20000, timeout: 20000})
          .then((loc) => {
            console.log(loc.longitude);
            console.log(loc.latitude);
          }, (e) => {
            console.log(e);
          })
      } else {
        console.log('Location services not enabled');
      }
    })

Without sending the location through the simulator, I’ll get a timeout while searching for my location. It actually works on a real device.

TLDR:

Geolocation errors I encountered and how to fix them:

  • GoogleApiAvailability of undefined: delete android folder in platforms folder, and run the android command again.
  • TypeError: format.replace is not a function: make sure you use console.log(...) with only one parameter. console.log(location.longitude, location.latitude) will cause this error.
  • Error: Timeout while searching for location!: explicitly send a location using the Extended controls in your Android emulator. If you try using a real device, it should work however.
5reactions
detorresrccommented, Feb 28, 2018

Hi guys I also encountered this problem, what I did was I deleted the android platform and added again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm test fails with error 'TypeError: Cannot read property ...
In reference to this issue #201, running npm test fails with 'cannot read property googleApiAvailability of undefined' on the line const ...
Read more >
Reference : TypeError: Cannot read property [property name ...
If a property doesn't exist in a object, accessing that property results in undefined and eventually a type error, if undefined is accessed ......
Read more >
Fixing error: cannot read property "values" from undefined
Typeerror : cannot read property “values” from undefined is one of the most persistent and frequent errors you can get when doing any...
Read more >
GoogleApiAvailability | Google Play services
Returns a human-readable string of the error code returned from isGooglePlayServicesAvailable(Context). static GoogleApiAvailability.
Read more >
Develop a Map Application using NativeScript and MapBox
JS: checking if geolocation is enabledJS: isEnabled error TypeError: Cannot read property 'GoogleApiAvailability' of undefinedJS: ...
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