The marker that I click on. this marker not open Info window but a another markers info window is open
below my code
public loadMap(){
this.geolocation.getCurrentPosition().then((position) => {
this.latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
this.mapOptions = {
center: this.latLng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map(this.mapElement.nativeElement, this.mapOptions);
this.nearbyPlace();
this.addMarkercurrentuserlocation();
}, (err) => {
alert('err '+err);
});
}
/*-----------------Find Nearby Place------------------------*/
public nearbyPlace(){
this.markers = [];
let service = new google.maps.places.PlacesService(this.map);
service.nearbySearch({
location: this.latLng,
radius: 300,
types: ['bank']
}, (results, status) => {
this.callback(results, status);
});
}
public callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
this.createMarker(results[i]);
}
}
}
public createMarker(place){
var placeLoc = place;
console.log('placeLoc',placeLoc)
this.markers = new google.maps.Marker({
map: this.map,
position: place.geometry.location,
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
//title: place.features[1].name
});
let infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(this.markers, 'click', () => {
this.ngZone.run(() => {
infowindow.setContent(place.name[1]);
infowindow.open(this.map, this.markers);
});
});
}
public addMarkercurrentuserlocation(){
let marker = new google.maps.Marker({
map: this.map,
animation: google.maps.Animation.DROP,
position: this.map.getCenter()
});
let content = "<h4>Me</h4>";
this.addInfoWindow(marker, content);
}
addInfoWindow(marker, content){
let infoWindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(marker, 'click', () => {
infoWindow.open(this.map, marker);
});
}
how can i fix that
Please help me
Sorry for poor English
Thanks