Tips on utilizing storage.set() within google.maps.events.addListener(marker, 'dragend', function() { }); in Ionic 3

google.maps.event.addListener(Marker, 'click', (function(Marker) {
  return function() {
    this.storage.set('mylocation', this.Marker.getPosition()); 
  }
})(Marker));

polyfills.js:3 Uncaught TypeError: Cannot read property 'set' of undefined

Encountering an issue when attempting to save storage in Ionic 3 using the data from a Google Maps marker dragend event.

Answer №1

An error occurred: Cannot read property 'set' of undefined

This indicates that the variable "storage" has not been defined. To resolve this issue, make sure to declare and import "storage" correctly in the constructor as shown in this guide: Ionic Storage Docs

import { Storage } from '@ionic/storage';

export class MyApp {
  constructor(private storage: Storage) { }

  ...

  // set a key/value
  this.storage.set('name', 'Max');

  // Or to get a key/value pair
  this.storage.get('age').then((val) => {
    console.log('Your age is', val);
  });
}

If the error is related to this.Marker.getPosition() being null, you may try implementing the solution suggested by Ahkil J:

google.maps.event.addListener(Marker, 'click', (function(Marker) {
  return function() {
    this.LastLat = Marker.position.lat();
    this.LastLng = Marker.position.lng();

    this.storage.set('mylocation', this.LastLat + this.LastLng);    
  }
})(Marker));

Answer №2

If you're encountering this issue, here's how you can resolve it. I came across the solution on this page about Ionic Framework dragend solution

google.maps.event.addListener(marker, 'dragend', () =>{ 
  this.LastLat= marker.position.lat();
  this.LastLng= marker.position.lng();

  this.storage.set('mylocation', this.LastLat);    
});

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

Utilizing class-validator for conditional validation failure

Implementing conditional validation in the class-validator library using the given example, I need to ensure that validation fails if the woodScrews property is assigned a value when the tool property is set to Tool.TapeMeasure. I've searched extensiv ...

JSX is restricted in files using the '.tsx' extension according to eslint rules (react/jsx-filename-extension)

When working in a .tsx file, why does eslint flag the following issue: The use of JSX is not permitted in files with the extension '.tsx' (eslint react/jsx-filename-extension) What steps can I take to adjust the eslint configuration and addres ...

The parameter of type 'void' cannot be assigned to the parameter of type 'PathParams'

Established the route handler and encountered an issue while integrating it into my route. import {Application, NextFunction} from 'express'; import {container} from 'tsyringe'; const routeConstantsArray = { }; const constants: any ...

Using alternate variables in the watchQuery() function in Apollo Angular will generate the cached data

Currently, I am implementing a feature in my project that allows users to access and analyze data based on various parameters such as year, location, and gender. Below is the code snippet that I have developed for this feature: this._querySubscription = ...

Why should TypeScript interfaces be utilized in Angular services for defining type information?

What are the benefits of creating an interface for an Angular service as opposed to simply exporting the service class and using that for type information? For example: class Dashboard { constructor(ui: IUiService){} } vs class Dashboard { cons ...

Issue: Generated JavaScript files not visible in Visual Studio when using TypeScript.Explanation: When working with

Is there a way to locate the JavaScript files generated from the TypeScript file in Visual Studio 2015? It seems that although the JavaScript files are present in File Explorer, they are not visible in the solution explorer. I attempted to add the _refer ...

Successfully generated files, now patiently awaiting typecheck results... encountering an issue with importing SASS modules

Issue Encountering a problem where adding SASS variables to TypeScript files causes the browser tab with an open devserver to hang, displaying Files successfully emitted, waiting for typecheck results.... Trying to figure out what's causing this iss ...

TypeScript NodeJS Error: Unable to access the 'address' property as it is undefined

Having just started using TypeScript, I am puzzled by the error it's throwing. The VanillaJS version works perfectly, but when I transferred it to TypeScript and checked my index.ts file, the same error persisted even after compiling the TS code usin ...

Embracing Typescript version 2.7 and above allows for utilizing multiple types within a parameter, enabling developers to efficiently handle specific properties

Imagine a scenario where a ChildClass is extending the ParentClass. You can view the code on Stackblitz here. The ChildClass simply adds a public property called "brainPower": class ParentClass{ _me: string; constructor() { this._me = "I'm ...

What is the syntax for defining a generic type in TypeScript when using the property name "type"?

Is there a way to declare a generic type GetAppActions where if T is equal to trigger, only the trigger data property is displayed, and vice versa? type GetAppActionType = 'trigger' | 'action' interface AppActionInputField {} type GetA ...

I am facing an issue with my ngx-translator in Ionic4 as it is unable to retrieve the current language

I am having an issue with the ngx-translator package where I am unable to set the default language in my application. Here is the code snippet from my app.module.ts: import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import ...

Checking the text both before and after clicking a link by using a method such as content verification

Currently, I am encountering an issue with validating the text on my links before and after they are clicked. If the link text reads "one two" before clicking and remains as "one two" after the click, then the test case passes. However, if the text change ...

There seems to be an issue with the TypeScript error: it does not recognize the property on the options

I have an item that looks like this: let options = {title: "", buttons: undefined} However, I would like to include a function, such as the following: options.open() {...} TypeScript is giving an error message: property does not exist on the options ty ...

What factors contribute to 'tslib' having more downloads than 'typecrypt'?

How is it possible that 'tslib', a library for 'typescript', has more downloads than 'typescript' itself? If one does not use 'typescript', then they cannot utilize 'tslib' as well. Just because someone us ...

"Transforming a Java byte array into a ReactJS video: Step-by-step guide

I am getting a file from a Java API server and need to convert it into a video using React JS. The Java API server converts the video file into a byte array using Files.readAllBytes(file) and I need to use this video file byte array to create a video fil ...

Change the type of an object to a different type

Within my class, I have set the type of range to IntervalRange. export class Test {range: IntervalRange;} Then, in the parent class, I initialize the value: export class TestInitializer { Create(){ return <Test>{ range: IntervalRange.i ...

Navigating an array using ngFor and encountering an error message saying, "Identifier not specified"

While using ngFor to iterate through an array, I encountered the following error message: "Identifier 'expenseitem' is not defined. The component declaration, template variable declarations, and element references do not contain such a memb ...

Exploring file functionalities in cordova and Ionic for seamless iOS and Android compatibility

To address this question, I have created a compatibility test project on GitHub. You can find it here. The initial state is configured specifically for the Ionic View application. Testing with Ionic Browser When running ionic serve, the output matches w ...

A guide on retrieving TypeScript mongoose/typegoose schema

Here is a defined schema for an account class AccountSchema; Below is the model declaration for the account const AccountClass: Model<AccountSchema & Document>; class Account extends AccountClass; Why isn't this functioning as expected? ...

From where does useTranslate fetch the translations?

I have started my journey to learn React with NextJS and recently purchased this amazing template. While exploring the src/pages/terms.tsx file, I came across some quite complex code. One thing that intrigued me was the question: What does the ? in conten ...