Troubleshooting Problem with Geo-location in Ionic 4

Recently, I've been attempting to create a code that will retrieve latitude and longitude from an Ionic-built app. Like many others, I initially used

https://ionicframework.com/docs/native/background-geolocation as my reference for writing the code.

Unfortunately, this plugin proved to be ineffective for me, so I am now seeking alternative methods, with or without using the plugin.

I started off by following the code provided in the Ionic 4 native documentation back in December 2018 when it was functional. However, upon revisiting my app today after some time, I encountered crashes. I attempted rewriting the code and experimenting with different versions of the plugin, but none seemed to work.


setBackgroundTracking(){
    this.backgroundGeolocation.configure(config)
          .then(() => {

            this.backgroundGeolocation.on('location').subscribe((location: BackgroundGeolocationResponse) => {
              console.log(location);

              // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
              // and the background-task may be completed.  You must do this regardless if your operations are successful or not.
              // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
              this.backgroundGeolocation.finish(); // FOR IOS ONLY
            });

          });


The above code is an exact copy paste from the documentation. and the code is buggy.

Property 'subscribe' does not exist on type 'Promise<any>'.ts(2339)

If you guys can fix the code or tell me another way to do it, please let me know. I have just been brainstorming would appreciate input/

Answer №1

It appears that the copying and pasting from the documentation did not go as planned:

this.backgroundGeolocation.configure(config)
  .then(() => {

    this.backgroundGeolocation.on('location').subscribe((location: BackgroundGeolocationResponse) => {
      console.log(location);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The functionality of allowEmpty : true in gulp 4.0 does not seem to be effective when dealing with

gulp.task("f1", () => { gulp.src([], {"allowEmpty": true}) .pipe(gulp.dest(location)); }) An error message pops up saying "Invalid glob argument:" when the code above is used. gulp.task("f1", () => { gulp.sr ...

Assign each active class name to the Tab components in React

I'm struggling to figure out how to apply an active class to each tab title so that it can have a distinct style when clicked. I'm looking for solutions on how to achieve this within these components, any help is greatly appreciated. App.tsx imp ...

Error: React - Unable to access the 'lazy' property because it is undefined

I used a helpful guide on the webpack website to incorporate TypeScript into my existing React App. However, upon launching the app, an error message pops up saying: TypeError: Cannot read property 'lazy' of undefined The version of React being ...

Is there a way to disable the camera on React-QR-Reader after receiving the result?

My experience with react-qr-reader has been smooth for scanning QR codes, however, I'm having trouble closing the camera after it's been opened. The LED indicator of the camera remains on even when not in use. I attempted using the getMedia func ...

Angular (Ionic): Updating component view with loop does not refresh

When utilizing *ngFor to repeat a component multiple times, the components displayed are not updating in the DOM as expected. Displaying the component within an ionic page: <ion-row *ngFor="let file of files; let i = index"> <app-add ...

Most effective methods for validating API data

Currently, I am working on developing an api using nestjs. However, I am facing some confusion when it comes to data validation due to the plethora of options available. For instance, should I validate data at the route level using schema validation (like ...

The map() function's splice operation unexpectedly removes only half of the array

I am currently working with an array that contains 146 objects, each object having its own unique id. My goal is to delete any objects from the array that do not have a matching id. I wrote a function to accomplish this task, however, it only works for hal ...

What is preventing me from utilizing maxLength with input fields?

Whenever I try to include maxLength in an input field, I encounter an error message stating "Invalid DOM property maxlength". Should I be using maxLength instead? Here's a link to the code: https://codesandbox.io/s/nkz2kwl7y0 ...

Testing TypeScript using Jasmine and Chutzpah within Visual Studio 2015

I am new to unit testing in AngularJS with TypeScript. I have been using jasmine and chutzpah for unit testing, but I encountered an error "ReferenceError: Can't find variable: angular". My test file looks like this: //File:test.ts ///<chutzpah_r ...

This TypeScript error occurs when the props are not compatible and cannot be assigned to

Hello fellow Internet dwellers! I am a novice in the world of coding and TypeScript, seeking some assistance here. I am attempting to extract an array of objects from props, transform it into a new object with specific information, and then return it - ho ...

Removing a dynamic component in Angular

Utilizing Angular dynamic components, I have successfully implemented a system to display toaster notifications through the creation of dynamic components. To achieve this, I have utilized the following: - ComponentFactoryResolve - EmbeddedViewRef - Ap ...

Discovering Type Definitions in Nuxt.js Project Without Manual Imports in VSCode: A Step-by-Step Guide

Having issues with VSCode not recognizing type definitions automatically in a Nuxt.js project with TypeScript. I'm looking to avoid manually importing types in every file. Here's my setup and the problem I'm facing: Configuration My tsconfi ...

Eliminating the nested API call within a loop

After making an API call to retrieve a set of data such as a list of users, I noticed that I am implementing a for loop and within it, I am making another API call to obtain each user's profile details based on their ID. I understand that this approac ...

TypeScript Generic Functions and Type Literals

Everything seems to be running smoothly: type fun = (uid: string) => string const abc: fun = value => value const efg = (callback:fun, value:string) =>callback(value) console.log(efg(abc, "123")) However, when we try to make it generic, we e ...

Accessing the 'comment' property within the .then() function is not possible if it is undefined

Why does obj[i] become undefined inside the .then() function? obj = [{'id': 1, 'name': 'john', 'age': '22', 'group': 'grA'}, {'id': 2, 'name': 'mike', &apo ...

Is app.component.ts necessary in an Angular 2 project?

Currently diving into Angular 2 and have a burning question on my mind. Do I really need the app.component.ts file in my project? Each of my folders has its own component and template, so I'm debating if the main component is necessary or if I can rem ...

what is a way to verify the presence of a variable in Angular?

Take a look at this sample code snippet: <li class="list-group-item" *ngIf="request.answer.user"> <a href="" class="d-flex flex-column align-items-center"> <span class="i ...

Troubleshooting compilation problems in Angular2 with nested components

I have created two components in Angular2 using TypeScript: app/app.component.ts import { Component } from '@angular/core'; @Component({ selector: 'my-app', styles : [` .parent { background : #c7c7c7; ...

default radio button selection problem

When working with reactive forms, I am facing an issue where the radio buttons are not being checked by default even though I am using form values for that purpose. Additionally, when I click on the first currency symbol, the numbers change but the default ...

Trying to access a private or protected member 'something' on a type parameter in Typescript is not permitted

class AnotherClass<U extends number> { protected anotherMethod(): void { } protected anotherOtherMethod(): ReturnType<this["anotherMethod"]> { // Private or protected member 'anotherMethod' cannot be accessed on a type para ...