Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] union should take date line into consideration
Browse files Browse the repository at this point in the history
  • Loading branch information
“osana” committed Feb 26, 2018
1 parent 5de373f commit bbd18d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,21 @@ public LatLngBounds union(LatLngBounds bounds) {
* @return BoundingBox
*/
public LatLngBounds union(final double latNorth, final double lonEast, final double latSouth, final double lonWest) {
return new LatLngBounds((this.latitudeNorth < latNorth) ? latNorth : this.latitudeNorth,
(this.longitudeEast < lonEast) ? lonEast : this.longitudeEast,
(this.latitudeSouth > latSouth) ? latSouth : this.latitudeSouth,
(this.longitudeWest > lonWest) ? lonWest : this.longitudeWest);
double north = (this.latitudeNorth < latNorth) ? latNorth : this.latitudeNorth;
double south = (this.latitudeSouth > latSouth) ? latSouth : this.latitudeSouth;

if (LatLngSpan.getLongitudeSpan(lonEast, this.longitudeWest) <
LatLngSpan.getLongitudeSpan(this.longitudeEast, lonWest)) {
return new LatLngBounds(north,
lonEast,
south,
this.longitudeWest);
}

return new LatLngBounds(north,
this.longitudeEast,
south,
lonWest);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.os.Parcelable;
import android.support.annotation.NonNull;

import com.mapbox.mapboxsdk.constants.GeometryConstants;

/**
* A geographical span defined by its latitude and longitude span.
*/
Expand Down Expand Up @@ -136,4 +138,20 @@ public int hashCode() {
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}

/**
* Get the absolute distance, in degrees, between the west and
* east boundaries of this LatLngBounds
*
* @return Span distance
*/
static double getLongitudeSpan(double east, double west) {
double longSpan = Math.abs(east - west);
if (east > west) {
return longSpan;
}

// shortest span contains antimeridian
return GeometryConstants.LONGITUDE_SPAN - longSpan;
}
}

0 comments on commit bbd18d3

Please sign in to comment.