Javascript 如何在google maps';标记';点击
我所拥有的: 我想要的是: 我的代码扩展了:Javascript 如何在google maps';标记';点击,javascript,typescript,google-maps,ionic-framework,google-maps-markers,Javascript,Typescript,Google Maps,Ionic Framework,Google Maps Markers,我所拥有的: 我想要的是: 我的代码扩展了: 我试过其他一些方法,但对我来说,直觉上,这是最有意义的。帮忙?请并感谢您。使用本地变量来表示此 因为此会根据其运行的上下文更改其值 public addMarker(lat: number, lng: number) { ... let that = this; google.maps.event.addListener(marker, 'click', function() { ... that.prese
我试过其他一些方法,但对我来说,直觉上,这是最有意义的。帮忙?请并感谢您。使用本地变量来表示
此
因为此
会根据其运行的上下文更改其值
public addMarker(lat: number, lng: number) {
...
let that = this;
google.maps.event.addListener(marker, 'click', function() {
...
that.presentAlert();
});
}
public addMarker(lat: number, lng: number) {
//let latLng = new google.maps.LatLng(lat, lng);
let latLng = new google.maps.LatLng(21.576, -158.271); // hiking
// spot
let marker = new google.maps.Marker({
map: this.map,
animation: google.maps.Animation.DROP,
position: latLng
});
this.markers.push(marker); // catch 'em all
google.maps.event.addListener(marker,'click',function() {
this.map.setZoom(15);
this.map.setCenter(marker.getPosition());
console.log('hello world');
this.presentAlert(); // ERROR core.js:9110 ERROR TypeError:
// this.presentAlert is not a function
});
}
presentAlert() {
this.alertCtrl.create({
header: 'Alert',
subHeader: 'Subtitle',
message: 'This is an alert message.',
buttons: ['OK']
}).then(alert=> {
alert.present();
});
}
public addMarker(lat: number, lng: number) {
...
let that = this;
google.maps.event.addListener(marker, 'click', function() {
...
that.presentAlert();
});
}