Error: Cannot read property 'GoogleApiAvailability' of undefined
See original GitHub issueFrom 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:
- Created 6 years ago
- Comments:9 (2 by maintainers)
Top 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 >
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
(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: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 useconsole.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.Hi guys I also encountered this problem, what I did was I deleted the android platform and added again.