Problem using geolocation getCurrentLocation


#1

I’m trying to get my current location. I have seen a couple of examples and can’t seem to find out what I’m doing wrong.

Error:

JS: Error: Cannot read property ‘GoogleApiAvailability’ of undefined

Code:

var geolocation = require("nativescript-geolocation");
exports.currentLocation = function() {  
    if (!geolocation.isEnabled()) {
        alert("You need to Enable GeoLocation!")
        return
    }

    geolocation.getCurrentLocation( {timeout: 5000} )
        .then(function (location) {
            console.log(location.latitude)
            console.log(location.longitude)
        }, function (e) {
            console.log("Error: " + e.message);
    });
}

#2

I believe you are using a real device for testing. Did you try a clean build after installing the module, make sure all dependencies are installed?


#3

Hi I am using an Android Emulator.
Details for emulator:
Name: Nexus5_API
CPU/ABI: Google APIs Intel Atom (x86)
Path: C:\Users\Gamer.android\avd\Nexus5_API.avd
Target: google_apis [Google APIs] (API level 27)
Skin: nexus_5x
SD Card: 100 MiB
hw.dPad: no
hw.lcd.height: 1920
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: Nexus 5X
vm.heapSize: 256
skin.dynamic: yes
hw.device.manufacturer: Google
hw.lcd.width: 1080
hw.gps: yes
hw.initialOrientation: Portrait
image.androidVersion.api: 27
hw.audioInput: yes
image.sysdir.1: system-images\android-27\google_apis\x86
tag.id: google_apis
showDeviceFrame: yes
hw.camera.back: none
hw.mainKeys: no
AvdId: Nexus5_API
hw.camera.front: none
hw.lcd.density: 420
avd.ini.displayname: Nexus5 API
hw.gpu.mode: auto
hw.device.hash2: MD5:bc5032b2a871da511332401af3ac6bb0
hw.ramSize: 1536
hw.trackBall: no
PlayStore.enabled: false
fastboot.forceColdBoot: no
hw.battery: yes
hw.sdCard: no
tag.display: Google APIs
runtime.network.latency: none
hw.keyboard: no
hw.sensors.proximity: yes
disk.dataPartition.size: 200M
hw.sensors.orientation: yes
avd.ini.encoding: UTF-8
hw.gpu.enabled: yes


#4

I don’t think Android emulators support GPS / has required Google Play libraries installed. You need a real device.


#5

I used my actual android phone. Still got the same error.


#6

Did you manage to solve this?


#7

as @manojdcoder mentioned
do a “tns platform clean android”