Iam working on an Ionic project where the requirement is to add google map in an ionic page with multiple markers. I followed some of the youtube tutorials and got succeeded in adding google map with one location marker. I want to add multiple location markers with different latitude and longitude values.
Below is the code i tried.
HTML:
<ion-content>
<div #mapElement class="map"></div>
</ion-content>
TS:
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
declare var google;
@Component({
selector: 'app-test',
templateUrl: './test.page.html',
styleUrls: ['./test.page.scss'],
})
export class TestPage implements OnInit {
@ViewChild('mapElement', {static:true}) mapRef: ElementRef;
constructor() { }
ngOnInit() {
}
ngAfterViewInit() {
const location = new google.maps.LatLng(17.385044,
78.486671);
const options = {
center:location,
zoom:10,
streetViewControl:false,
mapTypeId:'hybrid'
};
const map = new google.maps.Map(this.mapRef.nativeElement,options);
this.addMarker(location,map);
}
addMarker(position,map) {
return new google.maps.Marker({
position,
map
});
}
}
Please help me how can i add diffent markers for bangalore, chennai, mumbai locations with their latitude and longitude values.
thank you.