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

add max & min latitude and longitude constants to maps sdk #10780

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.os.Parcelable;
import android.support.annotation.FloatRange;

import com.mapbox.services.android.telemetry.constants.GeoConstants;
import com.mapbox.mapboxsdk.constants.GeometryConstants;


/**
Expand Down Expand Up @@ -105,20 +105,20 @@ protected LatLng(Parcel in) {
/**
* 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;
Expand All @@ -127,13 +127,13 @@ public void setLatitude(
/**
* 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() {
Expand All @@ -143,15 +143,15 @@ public double getLatitude() {
/**
* 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");
Expand All @@ -165,13 +165,13 @@ public void setLongitude(@FloatRange(from = GeoConstants.MIN_LONGITUDE, to = Geo
/**
* 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() {
Expand Down Expand Up @@ -204,7 +204,7 @@ public double getAltitude() {
* @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));
}


Expand Down Expand Up @@ -330,6 +330,6 @@ public double distanceTo(LatLng other) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -194,10 +194,10 @@ public String toString() {
* @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();
Expand Down Expand Up @@ -237,11 +237,16 @@ private static double lat_(int z, int y) {
}

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import android.os.Parcelable;

import com.mapbox.mapboxsdk.constants.GeometryConstants;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import com.mapbox.mapboxsdk.utils.MockParcel;
import com.mapbox.services.android.telemetry.constants.GeoConstants;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -276,13 +276,11 @@ public void testParcelable() {

@Test
public void fromTileID() {
//GeoConstants.MAX_LATITUDE is not defined to a high enough precision
double MAX_LATITUDE = 85.05112877980659;
LatLngBounds bounds = LatLngBounds.from(0, 0, 0);
assertEquals(-GeoConstants.MAX_LONGITUDE, bounds.getLonWest(), DELTA);
assertEquals(-MAX_LATITUDE, bounds.getLatSouth(), DELTA);
assertEquals(GeoConstants.MAX_LONGITUDE, bounds.getLonEast(), DELTA);
assertEquals(MAX_LATITUDE, bounds.getLatNorth(), DELTA);
assertEquals(GeometryConstants.MIN_LONGITUDE, bounds.getLonWest(), DELTA);
assertEquals(GeometryConstants.MIN_MERCATOR_LATITUDE, bounds.getLatSouth(), DELTA);
assertEquals(GeometryConstants.MAX_LONGITUDE, bounds.getLonEast(), DELTA);
assertEquals(GeometryConstants.MAX_MERCATOR_LATITUDE, bounds.getLatNorth(), DELTA);

bounds = LatLngBounds.from(10, 288, 385);
assertEquals(-78.75, bounds.getLonWest(), DELTA);
Expand Down