Hello there,
I’m using https://github.com/mapsplugin/cordova-plugin-googlemaps in my application. I’m able to diaplay multiple markers on Map. But not able to get custom data, when we click on particular marker. Can u please help me in that. The following code snippet that I’m using to dislpay multiple markers on map.
markersArr = [
{
title: 'markers',
customInfo: "Marker A",
icon: {
url: "./assets/imgs/marker.png",
size: {
width: 30,
height: 30
}
},
animation: GoogleMapsAnimation.BOUNCE,
position: {
lat: 52.489899,
lng: -2.01839
},
iconData: {
url: "./assets/imgs/marker-selected.png",
size: {
width: 30,
height: 40
}
}
},
{
title: 'markers',
customInfo: "Marker A",
icon: {
url: "./assets/imgs/marker.png",
size: {
width: 30,
height: 30
}
},
animation: 'DROP',
position: {
lat: 52.489899,
lng: -1.01839
},
iconData: {
url: "./assets/imgs/marker-selected.png",
size: {
width: 30,
height: 40
}
}
}
]
ionViewDidLoad() {
this.getCurrentLocation();
}
getCurrentLocation() {
this._geoLoc.getCurrentPosition().then((position) => {
let yourPosition: ILatLng = {
lat: 52.4773549, // position.coords.latitude,
lng: -2.003715 // position.coords.longitude
};
this.loadMap(this.markersArr);
}, (err) => {
console.log(err);
alert('location error');
});
}
loadMap(markersArr) {
let POINTS: BaseArrayClass<any> = new BaseArrayClass<any>(markersArr);
let bounds: ILatLng[] = POINTS.map((data: any, idx: number) => {
return data.position;
});
this.map = GoogleMaps.create('map_canvas', {
camera: {
target: bounds
}
});
POINTS.forEach((data: any) => {
// data.disableAutoPan = true;
let marker: Marker = this.map.addMarkerSync(data)
marker.on(GoogleMapsEvent.MARKER_CLICK,).subscribe(this.onMarkerClick);
// marker.on(GoogleMapsEvent.INFO_CLICK).subscribe(this.onMarkerClick);
});
}
onMarkerClick(params: any) {
alert("Marker Data: " + params.markerInfo);
let marker: Marker = <Marker>params[1];
let iconData: any = marker.get('iconData');
marker.setIcon(iconData);
}
Thanks