Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如何在google.maps.events.addListener(marker,dragend,function(){})中使用storage.set();在离子3中_Typescript_Events_Ionic Framework_Maps_Storage - Fatal编程技术网

Typescript 如何在google.maps.events.addListener(marker,dragend,function(){})中使用storage.set();在离子3中

Typescript 如何在google.maps.events.addListener(marker,dragend,function(){})中使用storage.set();在离子3中,typescript,events,ionic-framework,maps,storage,Typescript,Events,Ionic Framework,Maps,Storage,polyfills.js:3未捕获类型错误:无法读取未定义的属性“set” 当我尝试使用google maps marker dragend事件的响应在Ionic 3中设置存储时,我遇到了这个错误。对于出现此错误的用户,请按以下方式解决。我从这里找到的 无法读取未定义的属性“set” 这意味着“存储”是未定义的。 如果未定义存储,请确保在构造函数中声明它并正确导入,如下所示: 如果由于this.Marker.getPosition()为空而引发错误,您可以尝试使用Ahkil J的解决方案: im

polyfills.js:3未捕获类型错误:无法读取未定义的属性“set”


当我尝试使用google maps marker dragend事件的响应在Ionic 3中设置存储时,我遇到了这个错误。

对于出现此错误的用户,请按以下方式解决。我从这里找到的

无法读取未定义的属性“set”

这意味着“存储”是未定义的。 如果未定义存储,请确保在构造函数中声明它并正确导入,如下所示:

如果由于
this.Marker.getPosition()
为空而引发错误,您可以尝试使用Ahkil J的解决方案:

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);
  });
}
google.maps.event.addListener(marker, 'dragend', () =>{ 
  this.LastLat= marker.position.lat();
  this.LastLng= marker.position.lng();

  this.storage.set('mylocation', this.LastLat);    
});
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);
  });
}
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));