如何在没有GoogleMaps的情况下计算边界中心?

Eri*_*rik 3 google-maps latitude-longitude bounds

我有以下界限:

var bounds = {
    southwest: {lat: 54.69726685890506, lng: -2.7379201682812226},
    northeast: {lat: 55.38942944437183, lng: -1.2456105979687226}
};
Run Code Online (Sandbox Code Playgroud)

通过使用谷歌地图API,我可以计算上面的界限,如下所示:

// returns (55.04334815163844, -1.9917653831249726)
(new google.maps.LatLngBounds(bounds.southeast, bounds.northeast)).getCenter();
Run Code Online (Sandbox Code Playgroud)

如何在不使用google.maps.LatLngBounds.getCenter数学的情况下计算边界中心?

我需要编写"魔术"函数,返回相同的中心纬度,如下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) 
Run Code Online (Sandbox Code Playgroud)

geo*_*zip 11

var bounds = {
    southwest: {lat: 54.69726685890506, lng: -2.7379201682812226},
    northeast: {lat: 55.38942944437183, lng: -1.2456105979687226}
};

center lat = (southwest.lat + northeast.lat)/2 = 55.043348151638
center lng = (southwest.lng + northeast.lng)/2 = -1.991765383125
Run Code Online (Sandbox Code Playgroud)