This work for me in Angular 9:
import {GoogleMap, GoogleMapsModule} from "@angular/google-maps";
@ViewChild('Map') Map: GoogleMap; /* Element Map */
locations = [
{ lat: 7.423568, lng: 80.462287 },
{ lat: 7.532321, lng: 81.021187 },
{ lat: 6.117010, lng: 80.126269 }
];
constructor() {
var bounds = new google.maps.LatLngBounds();
setTimeout(() => {
for (let u in this.locations) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(this.locations[u].lat,
this.locations[u].lng),
});
bounds.extend(marker.getPosition());
}
this.Map.fitBounds(bounds)
}, 200)
}
And it automatically centers the map according to the indicated positions.
Result: