I have the following bounds:
var bounds = {
southwest: {lat: 54.69726685890506, lng: -2.7379201682812226},
northeast: {lat: 55.38942944437183, lng: -1.2456105979687226}
};
By using google maps API I could calculate canter of the bounds above like the following:
// returns (55.04334815163844, -1.9917653831249726)
(new google.maps.LatLngBounds(bounds.southeast, bounds.northeast)).getCenter();
How could calculate center of bounds without using google.maps.LatLngBounds.getCenter
but Math?
I need to write "magic" function that returns the same center lat, lng like google.maps.LatLngBounds.getCenter
:
function getBoundsCenter(bounds) {
// need to calculate and return center of passed bounds;
}
var center = getBoundsCenter(bounds); // center should be (55.04334815163844, -1.9917653831249726)