Android Open Source - WhatsUp Geo Point Util






From Project

Back to project page WhatsUp.

License

The source code is released under:

GNU General Public License

If you think the Android project WhatsUp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package nu.placebo.whatsup.util;
/*w  w  w. java 2s  .c  om*/
import android.os.Bundle;

import com.google.android.maps.GeoPoint;

public class GeoPointUtil {

  /**
   * Converts two GeoPoints and delivers an array with decimal degree doubles
   * in the order:
   * 
   * minLat, minLong, maxLat, maxLong
   * 
   * The coordinates will be ordered in this manner regardless of which
   * coordinate belongs to which GeoPoint
   * 
   * @param a
   * @param b
   * @return [minLat, minLong, maxLat, maxLong]
   */
  public static double[] convertAreaToDoubles(GeoPoint a, GeoPoint b) {
    double[] result = new double[4];

    result[0] = ((double) Math.min(a.getLatitudeE6(), b.getLatitudeE6())) / 1000000;
    result[1] = ((double) Math.min(a.getLongitudeE6(), b.getLongitudeE6())) / 1000000;
    result[2] = ((double) Math.max(a.getLatitudeE6(), b.getLatitudeE6())) / 1000000;
    result[3] = ((double) Math.max(a.getLongitudeE6(), b.getLongitudeE6())) / 1000000;

    return result;
  }

  /**
   * Converts a single GeoPoint to an array of decimal degree doubles
   * 
   * 
   * @param a
   * @return [lat, long]
   */
  public static double[] convertGeoPointToDoubles(GeoPoint a) {
    double[] result = new double[2];

    result[0] = ((double) a.getLatitudeE6()) / 1000000;
    result[1] = ((double) a.getLongitudeE6()) / 1000000;

    return result;
  }

  /**
   * Creates two GeoPoints with the center of the map, latitude span and longitude span
   * 
   * @param center - center of the current mapview
   * @param latSpan - latitude span from bottom to top
   * @param longSpan - longitude span from left to right
   * @return GeoPoint[] with two GeoPoints representing the bottom-left and top-right coordinates 
   */
  public static GeoPoint[] getBottomLeftToTopRightPoints(GeoPoint center,  int latSpan, int longSpan) {
    int bottom = center.getLatitudeE6() - (latSpan / 2);
    int top = center.getLatitudeE6() + (latSpan / 2);
    int left = center.getLongitudeE6() - (longSpan / 2);
    int right = center.getLongitudeE6() + (longSpan / 2);
    return new GeoPoint[] { new GeoPoint(bottom, left), new GeoPoint(top, right) };
  }

  /**
   * Convenience method for packing a GeoPoint in a Bundle (android.os)
   * 
   * 
   * 
   * @see #popGeoPoint(Bundle)
   * @see #bundleHasGeoPoint(Bundle)
   * @param p
   * @return Bundle with packaged GeoPoint
   */
  public static Bundle pushGeoPoint(GeoPoint p) {
    Bundle bundle = new Bundle();
    bundle.putInt("lat", p.getLatitudeE6());
    bundle.putInt("long", p.getLongitudeE6());

    return bundle;
  }

  /**
   * Convenience method for unpacking a GeoPoint from a android.os.Bundle bundle must be
   * packed according to local standards.
   * 
   * @param bundle
   * @return GeoPoint
   */
  public static GeoPoint popGeoPoint(Bundle bundle) {
    GeoPoint p = new GeoPoint(bundle.getInt("lat"), bundle.getInt("long"));

    return p;
  }

  /**
   * Returns whether the bundle contains a properly packaged GeoPoint
   * according to local standards.
   * 
   * @param b
   * @return
   */
  public static boolean bundleHasGeoPoint(Bundle b) {
    return b.containsKey("lat") && b.containsKey("long");
  }
}




Java Source Code List

nu.placebo.whatsup.activity.AnnotationActivity.java
nu.placebo.whatsup.activity.CreateAnnotationActivity.java
nu.placebo.whatsup.activity.CreateCommentActivity.java
nu.placebo.whatsup.activity.ListViewActivity.java
nu.placebo.whatsup.activity.LogInActivity.java
nu.placebo.whatsup.activity.LoginRegTabActivity.java
nu.placebo.whatsup.activity.MapViewActivity.java
nu.placebo.whatsup.activity.Marker.java
nu.placebo.whatsup.activity.MenuHelper.java
nu.placebo.whatsup.activity.PositionPickerActivity.java
nu.placebo.whatsup.activity.RefPointActivity.java
nu.placebo.whatsup.activity.RegisterActivity.java
nu.placebo.whatsup.android.os.AsyncTask.java
nu.placebo.whatsup.balloon.BalloonItemizedOverlay.java
nu.placebo.whatsup.balloon.BalloonOverlayView.java
nu.placebo.whatsup.constants.Constants.java
nu.placebo.whatsup.ctrl.SessionHandler.java
nu.placebo.whatsup.datahandling.DataProvider.java
nu.placebo.whatsup.datahandling.DataReturnListener.java
nu.placebo.whatsup.datahandling.DataReturn.java
nu.placebo.whatsup.datahandling.DatabaseConnectionLayer.java
nu.placebo.whatsup.datahandling.DatabaseHelper.java
nu.placebo.whatsup.model.Annotation.java
nu.placebo.whatsup.model.Comment.java
nu.placebo.whatsup.model.ExtendedOverlayItem.java
nu.placebo.whatsup.model.GeoLocation.java
nu.placebo.whatsup.model.ListMarker.java
nu.placebo.whatsup.model.ReferencePoint.java
nu.placebo.whatsup.model.SessionInfo.java
nu.placebo.whatsup.network.AbstractNetworkOperation.java
nu.placebo.whatsup.network.Action.java
nu.placebo.whatsup.network.AnnotationCreate.java
nu.placebo.whatsup.network.AnnotationRetrieve.java
nu.placebo.whatsup.network.CommentCreate.java
nu.placebo.whatsup.network.GeoLocationsRetrieve.java
nu.placebo.whatsup.network.Login.java
nu.placebo.whatsup.network.NetworkCalls.java
nu.placebo.whatsup.network.NetworkOperationListener.java
nu.placebo.whatsup.network.NetworkOperation.java
nu.placebo.whatsup.network.NetworkTask.java
nu.placebo.whatsup.network.OperationResult.java
nu.placebo.whatsup.network.RegisterOperation.java
nu.placebo.whatsup.network.SessionTest.java
nu.placebo.whatsup.util.GeoPointUtil.java
nu.placebo.whatsup.util.Geodetics.java
nu.placebo.whatsup.util.ValidationUtil.java
nu.placebo.whatsuptest.TestStarter.java
nu.placebo.whatsuptest.activitytest.AnnotationActivityTest.java
nu.placebo.whatsuptest.activitytest.ListViewActivityTest.java
nu.placebo.whatsuptest.activitytest.MapViewActivityTest.java
nu.placebo.whatsuptest.networktest.NetworkTest.java
nu.placebo.whatsuptest.utiltest.GeoPointUtilTest.java
nu.placebo.whatsuptest.utiltest.GeodeticsTest.java
nu.placebo.whatsuptest.utiltest.ValidationTest.java