コード例 #1
0
 /**
  * Calculates the span of bounds and returns it in a String. A span is two values which are
  * latitude and longitude length between each parts of bounds. Example : -SW.lat = 1 -SW.lng = 10
  * -NE.lat = 5 -NE.lng = 50 -> lat span = NE.lat - SW.lat = 5 - 1 = 4 -> lng span = NE.lng -
  * SW.lng = 50 - 10 = 40
  *
  * @return span formated in a string
  */
 public String toSpan() {
   return new StringBuffer("")
       .append(mNe.getLat() - mSw.getLat())
       .append(",")
       .append(mNe.getLng() - mSw.getLng())
       .toString();
 }
コード例 #2
0
 @Test
 public void equals() {
   double lat = 90, lng = 180;
   LatLng point = LatLng.newInstance(lat, lng);
   Map<LatLng, String> map = new HashMap<LatLng, String>();
   map.put(point, "point");
   Assert.assertEquals("point", map.get(LatLng.newInstance(lat, lng)));
 }
コード例 #3
0
 /**
  * Creates new SW and NE to create union with another entire LatLngBounds.
  *
  * @param other Other bounds to make union
  */
 public void union(LatLngBounds other) {
   mSw =
       new LatLng(
           Math.min(mSw.getLat(), other.getSw().getLat()),
           Math.min(mSw.getLng(), other.getSw().getLng()));
   mNe =
       new LatLng(
           Math.max(mNe.getLat(), other.getNe().getLat()),
           Math.max(mNe.getLng(), other.getNe().getLng()));
   calculateCenter();
 }
コード例 #4
0
 private static boolean throwsException(double lat, double lng) {
   try {
     LatLng.newInstance(lat, lng);
     return false;
   } catch (Exception e) {
     return true;
   }
 }
コード例 #5
0
 @Override
 public boolean equals(Object o) {
   // Return true if the objects are identical.
   if (this == o) {
     //		     PLog.i("equals","Same object");
     return true;
   }
   // Return false if the other object has the wrong type.
   if (!(o instanceof LatLngBounds)) {
     return false;
   }
   // Cast to the appropriate type
   LatLngBounds lhs = (LatLngBounds) o;
   // Check each field. Primitive fields, reference fields, and nullable reference
   // fields are all treated differently.
   return mSw.equals(lhs.mSw) && mNe.equals(lhs.mNe) && mCenter.equals(lhs.mCenter);
 }
コード例 #6
0
 /**
  * Extends bounds to the LatLng passed in parameter, if this one is not contained in bounds.
  *
  * @param point LatLng to include in bounds
  * @return LatLng
  */
 public void extend(LatLng point) {
   if (!contains(point)) {
     mSw =
         new LatLng(
             Math.min(mSw.getLat(), point.getLat()), Math.min(mSw.getLng(), point.getLng()));
     mNe =
         new LatLng(
             Math.max(mNe.getLat(), point.getLat()), Math.max(mNe.getLng(), point.getLng()));
     calculateCenter();
   }
 }
コード例 #7
0
 /**
  * Returns if yes or not the given LatLng is contained in bounds.
  *
  * @param latlng LatLng to test
  * @return true if LatLng is contained, false otherwise
  */
 public boolean contains(LatLng latlng) {
   double lat = latlng.getLat();
   double lng = latlng.getLng();
   return (lat >= mSw.getLat()
       && lng >= mSw.getLng()
       && lat <= mNe.getLat()
       && lng <= mNe.getLng());
 }
コード例 #8
0
  @Test
  public void compareTo() {
    LatLng p1 = LatLng.newInstance(90, -180);
    LatLng p2 = LatLng.newInstance(-90, 180);
    LatLng p3 = LatLng.newInstance(90, -180);
    LatLng p4 = LatLng.newInstance(-90, -180);

    Assert.assertEquals(1, p1.compareTo(p2));
    Assert.assertEquals(-1, p2.compareTo(p1));

    Assert.assertEquals(0, p1.compareTo(p3));
    Assert.assertEquals(0, p3.compareTo(p1));

    Assert.assertEquals(1, p1.compareTo(p2));
    Assert.assertEquals(1, p2.compareTo(p4));
    Assert.assertEquals(1, p1.compareTo(p4));
  }
コード例 #9
0
 public FloatLatLng(LatLng ll) {
   this.lat = ll.getLat();
   this.lng = ll.getLng();
 }
コード例 #10
0
 @Override
 public LatLng calculateMidpoint(LatLng other) {
   return new FloatLatLng((lat + other.getLat()) / 2.0, (lng + other.getLng()) / 2.0);
 }
コード例 #11
0
 /**
  * Calculates LatLng SW and NE when center and latSpanE6 and lngSpanE6 are known.
  *
  * @param latSpan Latitude span between SW lat and NE lat
  * @param latSpan Latitude span between SW lng and NE lng
  */
 private void calculateBounds(double latSpan, double lngSpan) {
   mSw = new LatLng(mCenter.getLat() - latSpan, mCenter.getLng() - lngSpan);
   mNe = new LatLng(mCenter.getLat() + latSpan, mCenter.getLng() + lngSpan);
 }
コード例 #12
0
 /** Calculates LatLng center when SW and NE are known. */
 private void calculateCenter() {
   double latCenter = (mSw.getLat() + mNe.getLat()) / 2;
   double lngCenter = (mSw.getLng() + mNe.getLng()) / 2;
   ;
   mCenter = new LatLng(latCenter, lngCenter);
 }
コード例 #13
0
 public int getLngSpanE6() {
   return (int) (Math.abs(mNe.getLng() - mSw.getLng()) * 1000000);
 }
コード例 #14
0
 /**
  * Returns center of theses bounds.
  *
  * @return Center LatLng
  */
 public LatLng getCenter() {
   return mCenter.clone();
 }
コード例 #15
0
 /**
  * Returns North East of theses bounds.
  *
  * @return North East LatLng
  */
 public LatLng getNe() {
   return mNe.clone();
 }
コード例 #16
0
 /**
  * Returns South West of theses bounds.
  *
  * @return South West LatLng
  */
 public LatLng getSw() {
   return mSw.clone();
 }