add max & min latitude and longitude constants to maps sdk

add max & min latitude and longitude constants to maps sdk  that are independent of Mercator projection

closes #10780
This commit is contained in:
Osana Babayan
2018-01-02 12:43:27 -05:00
committed by GitHub
parent 6ce38ccc6f
commit 814c87fbab
4 changed files with 103 additions and 37 deletions

View File

@@ -0,0 +1,63 @@
package com.mapbox.mapboxsdk.constants;
/**
* Contains constants used throughout the sdk classes.
*
* @since 6.0.0
*/
public class GeometryConstants {
/**
* The <a href='http://en.wikipedia.org/wiki/Earth_radius#Equatorial_radius'>equatorial radius</a>
* value in meters
*
* @since 6.0.0
*/
public static final int RADIUS_EARTH_METERS = 6378137;
/**
* This constant represents the lowest longitude value available to represent a geolocation.
*
* @since 6.0.0
*/
public static final double MIN_LONGITUDE = -180;
/**
* This constant represents the highest longitude value available to represent a geolocation.
*
* @since 6.0.0
*/
public static final double MAX_LONGITUDE = 180;
/**
* This constant represents the lowest latitude value available to represent a geolocation.
*
* @since 6.0.0
*/
public static final double MIN_LATITUDE = -90;
/**
* This constant represents the highest latitude value available to represent a geolocation.
*
* @since 6.0.0
*/
public static final double MAX_LATITUDE = 90;
/**
* Maximum latitude value in Mercator projection.
*
* @since 6.0.0
*/
public static final double MAX_MERCATOR_LATITUDE = 85.05112877980659;
/**
* Minimum latitude value in Mercator projection.
*
* @since 6.0.0
*/
public static final double MIN_MERCATOR_LATITUDE = -85.05112877980659;
private GeometryConstants() {
// Private constructor to prevent initializing of this class.
}
}

View File

@@ -5,7 +5,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
import com.mapbox.services.android.telemetry.constants.GeoConstants;
import com.mapbox.mapboxsdk.constants.GeometryConstants;
/**
@@ -105,20 +105,20 @@ public class LatLng implements ILatLng, Parcelable {
/**
* Set the latitude, in degrees.
* <p>
* This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and
* {@link GeoConstants#MAX_LATITUDE}
* This value is in the range of [-90, 90], see {@link GeometryConstants#MIN_LATITUDE} and
* {@link GeometryConstants#MAX_LATITUDE}
* </p>
*
* @param latitude the latitude value in degrees
* @see GeoConstants#MIN_LATITUDE
* @see GeoConstants#MAX_LATITUDE
* @see GeometryConstants#MIN_LATITUDE
* @see GeometryConstants#MAX_LATITUDE
*/
public void setLatitude(
@FloatRange(from = GeoConstants.MIN_LATITUDE, to = GeoConstants.MAX_LATITUDE) double latitude) {
@FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latitude) {
if (Double.isNaN(latitude)) {
throw new IllegalArgumentException("latitude must not be NaN");
}
if (Math.abs(latitude) > 90.0) {
if (Math.abs(latitude) > GeometryConstants.MAX_LATITUDE) {
throw new IllegalArgumentException("latitude must be between -90 and 90");
}
this.latitude = latitude;
@@ -127,13 +127,13 @@ public class LatLng implements ILatLng, Parcelable {
/**
* Get the latitude, in degrees.
* <p>
* This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and
* {@link GeoConstants#MAX_LATITUDE}
* This value is in the range of [-90, 90], see {@link GeometryConstants#MIN_LATITUDE} and
* {@link GeometryConstants#MAX_LATITUDE}
* </p>
*
* @return the latitude value in degrees
* @see GeoConstants#MIN_LATITUDE
* @see GeoConstants#MAX_LATITUDE
* @see GeometryConstants#MIN_LATITUDE
* @see GeometryConstants#MAX_LATITUDE
*/
@Override
public double getLatitude() {
@@ -143,15 +143,15 @@ public class LatLng implements ILatLng, Parcelable {
/**
* Set the longitude, in degrees.
* <p>
* This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and
* {@link GeoConstants#MAX_LONGITUDE}
* This value is in the range of [-180, 180], see {@link GeometryConstants#MIN_LONGITUDE} and
* {@link GeometryConstants#MAX_LONGITUDE}
* </p>
*
* @param longitude the longitude value in degrees
* @see GeoConstants#MIN_LONGITUDE
* @see GeoConstants#MAX_LONGITUDE
* @see GeometryConstants#MIN_LONGITUDE
* @see GeometryConstants#MAX_LONGITUDE
*/
public void setLongitude(@FloatRange(from = GeoConstants.MIN_LONGITUDE, to = GeoConstants.MAX_LONGITUDE)
public void setLongitude(@FloatRange(from = GeometryConstants.MIN_LONGITUDE, to = GeometryConstants.MAX_LONGITUDE)
double longitude) {
if (Double.isNaN(longitude)) {
throw new IllegalArgumentException("longitude must not be NaN");
@@ -165,13 +165,13 @@ public class LatLng implements ILatLng, Parcelable {
/**
* Get the longitude, in degrees.
* <p>
* This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and
* {@link GeoConstants#MAX_LONGITUDE}
* This value is in the range of [-180, 180], see {@link GeometryConstants#MIN_LONGITUDE} and
* {@link GeometryConstants#MAX_LONGITUDE}
* </p>
*
* @return the longitude value in degrees
* @see GeoConstants#MIN_LONGITUDE
* @see GeoConstants#MAX_LONGITUDE
* @see GeometryConstants#MIN_LONGITUDE
* @see GeometryConstants#MAX_LONGITUDE
*/
@Override
public double getLongitude() {
@@ -204,7 +204,7 @@ public class LatLng implements ILatLng, Parcelable {
* @return new LatLng object with wrapped Longitude
*/
public LatLng wrap() {
return new LatLng(latitude, wrap(longitude, GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE));
return new LatLng(latitude, wrap(longitude, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE));
}
@@ -330,6 +330,6 @@ public class LatLng implements ILatLng, Parcelable {
final double t3 = Math.sin(a1) * Math.sin(b1);
final double tt = Math.acos(t1 + t2 + t3);
return GeoConstants.RADIUS_EARTH_METERS * tt;
return GeometryConstants.RADIUS_EARTH_METERS * tt;
}
}

View File

@@ -5,8 +5,8 @@ import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.constants.GeometryConstants;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import com.mapbox.services.android.telemetry.constants.GeoConstants;
import java.util.ArrayList;
import java.util.List;
@@ -48,8 +48,8 @@ public class LatLngBounds implements Parcelable {
*/
public static LatLngBounds world() {
return new LatLngBounds.Builder()
.include(new LatLng(GeoConstants.MAX_LATITUDE, GeoConstants.MAX_LONGITUDE))
.include(new LatLng(GeoConstants.MIN_LATITUDE, GeoConstants.MIN_LONGITUDE))
.include(new LatLng(GeometryConstants.MAX_LATITUDE, GeometryConstants.MAX_LONGITUDE))
.include(new LatLng(GeometryConstants.MIN_LATITUDE, GeometryConstants.MIN_LONGITUDE))
.build();
}
@@ -194,10 +194,10 @@ public class LatLngBounds implements Parcelable {
* @return LatLngBounds
*/
static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
double minLat = 90;
double minLon = 180;
double maxLat = -90;
double maxLon = -180;
double minLat = GeometryConstants.MAX_LATITUDE;
double minLon = GeometryConstants.MAX_LONGITUDE;
double maxLat = GeometryConstants.MIN_LATITUDE;
double maxLon = GeometryConstants.MIN_LONGITUDE;
for (final ILatLng gp : latLngs) {
final double latitude = gp.getLatitude();
@@ -237,11 +237,16 @@ public class LatLngBounds implements Parcelable {
}
private static double lon_(int z, int x) {
return x / Math.pow(2.0, z) * 360.0 - GeoConstants.MAX_LONGITUDE;
return x / Math.pow(2.0, z) * 360.0 - GeometryConstants.MAX_LONGITUDE;
}
/**
* Constructs a LatLngBounds from a Tile identifier.
*
* Returned bounds will have latitude in the range of Mercator projection.
* @see GeometryConstants#MIN_MERCATOR_LATITUDE
* @see GeometryConstants#MAX_MERCATOR_LATITUDE
*
* @param z Tile zoom level.
* @param x Tile X coordinate.
* @param y Tile Y coordinate.