NativeScript / nativescript-geolocation

Geolocation plugin to use for getting current location, monitor movement, etc
Apache License 2.0
139 stars 77 forks source link

Cannot read property 'osVersion' of undefined at iOS #270

Open zabi90 opened 3 years ago

zabi90 commented 3 years ago

Hi, I just created new NativeScript with Angular shared code project and added nativescript-geolocation dependencies. It is working fine so far inside android but giving error Cannot read property 'osVersion' of undefined at iOS when i used this method geolocation.enableLocationRequest(true, true) Package.json

{
    "name": "HelloNativeScriptAngular",
    "main": "main.tns.js",
    "version": "0.0.0",
    "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "android": "tns run android --no-hmr",
        "ios": "tns run ios --no-hmr",
        "mobile": "tns run",
        "preview": "tns preview",
        "ngcc": "ngcc --properties es2015 module main --first-only",
        "postinstall": "npm run ngcc"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "~10.1.0",
        "@angular/common": "~10.1.0",
        "@angular/compiler": "~10.1.0",
        "@angular/core": "~10.1.0",
        "@angular/forms": "~10.1.0",
        "@angular/platform-browser": "~10.1.0",
        "@angular/platform-browser-dynamic": "~10.1.0",
        "@angular/router": "~10.1.0",
        "@nativescript/angular": "~10.1.0",
        "@nativescript/core": "~7.0.0",
        "@nativescript/theme": "~2.5.0",
        "core-js": "^3.6.0",
        "nativescript-geolocation": "^5.1.0",
        "reflect-metadata": "~0.1.12",
        "rxjs": "~6.6.0",
        "tslib": "1.10.0",
        "zone.js": "~0.11.1"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "~0.1001.0",
        "@angular/cli": "~10.1.0",
        "@angular/compiler-cli": "~10.1.0",
        "@nativescript/android": "7.0.0",
        "@nativescript/ios": "7.0.1",
        "@nativescript/tslint-rules": "~0.0.5",
        "@nativescript/webpack": "~3.0.0",
        "@types/jasmine": "~3.5.0",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "^12.11.1",
        "codelyzer": "^5.1.2",
        "jasmine-core": "~3.5.0",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~4.4.1",
        "karma-chrome-launcher": "~3.1.0",
        "karma-coverage-istanbul-reporter": "~2.1.0",
        "karma-jasmine": "~3.0.1",
        "karma-jasmine-html-reporter": "^1.4.2",
        "protractor": "~5.4.3",
        "ts-node": "~8.3.0",
        "tslint": "~6.1.0",
        "typescript": "~3.9.0"
    }
}

and my component code is

import { Component, OnInit } from '@angular/core';

import * as geolocation from "nativescript-geolocation";
 import { Accuracy } from "@nativescript/core/ui/enums";

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css'],
})
export class HomeComponent implements OnInit {
  title = 'HelloNativeScriptAngular';

  constructor() { }

  ngOnInit() {
  }

  public enableLocationTap(){
      geolocation.isEnabled().then(function (isEnabled) {
        if (!isEnabled) {
            geolocation.enableLocationRequest(true, true).then(() => {
                console.log("User Enabled Location Service");
            }, (e) => {
                console.log("Error: " + (e.message || e));
            }).catch(ex => {
                console.log("Unable to Enable Location", ex);
            });
        }
    }, function (e) {
        console.log("Error: " + (e.message || e));
    });
  }
}
nickolanack commented 3 years ago

Some minor changes to this library are required (imports etc) to support nativescript 7. I did submit a PR, although it likely requires some care (backward compatibility issues) #268

SKTAR commented 3 years ago

Having the same issue here…

bellalMohamed commented 3 years ago

The plugin is already updated for {N} 7, it's been moved under new scope like all other NativeScript plugins.

https://www.npmjs.com/package/@nativescript/geolocation

you can install it with npm

npm i @nativescript/geolocation

and replace

import * as Geolocation from 'nativescript-geolocation'; // old

import * as Geolocation from '@nativescript/geolocation'; // new
saibbyweb commented 3 years ago

Using @nativescript/geolocation fixes the problem. This information should be in the readme of this repo.