function calculateBounds(points) {
const amount = points.length;
if (amount === 0) {
return [];
}
let northeast = Object.assign({}, points[0]);
let southwest = Object.assign({}, points[0]);
for (let i = 1; i < amount; ++i) {
let point = points[i];
['lat', 'lng'].forEach((c) => {
northeast[c] = Math.min(northeast[c], point[c]);
southwest[c] = Math.max(southwest[c], point[c]);
});
}
return new google.maps.LatLngBounds(
new google.maps.LatLng(northeast.lat,northeast.lng),
new google.maps.LatLng(southwest.lat,southwest.lng)
);
}
const points = [
{lat: 55.3, lng: 36.24},
{lat: 53.1, lng: 35.39},
{lat: 57.7, lng: 39.16}
];
const bounds = calculateBounds(points);
bounds.getCenter();