LatLngBounds implements Parcelable { @NonNull public LatLng getCenter() { double midLat = (this.southwest.getLatitude() + this.northeast.getLatitude()) / 2.0D; double neLng = this.northeast.getLongitude(); double swLng = this.southwest.getLongitude(); double midLng; if (swLng <= neLng) { midLng = (neLng + swLng) / 2.0D; } else { midLng = (neLng + 360.0D + swLng) / 2.0D; } return new LatLng(midLat, midLng); } LatLngBounds(@NonNull LatLng southwest, @NonNull LatLng northeast); private  LatLngBounds(Parcel in); @NonNull LatLng getSouthwest(); @NonNull LatLng getNortheast(); boolean contains(LatLng point); @NonNull LatLngBounds including(@NonNull LatLng point); @NonNull LatLng getCenter(); @Override int describeContents(); @Override void writeToParcel(Parcel parcel, int i); static final Parcelable.Creator<LatLngBounds> CREATOR; }
@Test public void getCenter_shouldReturnCorrectCenter() { LatLng pointA = new LatLng(40, 50); LatLng pointB = new LatLng(-40, -50); LatLngBounds bounds = new LatLngBounds.Builder() .include(pointA) .include(pointB) .build(); LatLng center = bounds.getCenter(); assertThat(center.getLatitude()).isEqualTo(0); assertThat(center.getLongitude()).isEqualTo(0); }