Android Open Source - android-usable-location-privacy Coordinate






From Project

Back to project page android-usable-location-privacy.

License

The source code is released under:

Apache License

If you think the Android project android-usable-location-privacy 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

/*
 * Copyright (C) 2014 B. Henne, C. Kater,
 *   Distributed Computing & Security Group,
 *   Leibniz Universitaet Hannover, Germany
 */*  ww  w .ja va 2  s  . c om*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.locationprivacy.model;

import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Represents a geographic coordinate (latitude, longitude, altitude)
 * 
 * @author Christian Kater
 * 
 */
public class Coordinate implements Parcelable {
  /** Longitude */
  public double longitude;
  /** Latitude */
  public double latitude;

  /** Altitude */
  public double altitude;

  public static final Parcelable.Creator<Coordinate> CREATOR = new Parcelable.Creator<Coordinate>() {

    @Override
    public Coordinate createFromParcel(Parcel source) {
      return new Coordinate(source);
    }

    @Override
    public Coordinate[] newArray(int size) {
      return new Coordinate[size];
    }
  };

  /**
   * Creates new instance of Coordinate
   * 
   * @param longitude
   *            the longitude
   * @param latitude
   *            the latitude
   * @param altitude
   *            the altitude
   */
  public Coordinate(double longitude, double latitude, double altitude) {
    super();
    this.longitude = longitude;
    this.latitude = latitude;
    this.altitude = altitude;
  }

  /**
   * Creates new instance of Coordinate with altitude 0.
   * 
   * @param longitude
   *            the longitude
   * @param latitude
   *            the latitude
   */
  public Coordinate(double longitude, double latitude) {
    super();
    this.longitude = longitude;
    this.latitude = latitude;
    this.altitude = 0;
  }

  /**
   * Creates new instance of Coordinate
   * 
   * @param in
   *            Parcel object containing lat, lon, alt
   */
  public Coordinate(Parcel in) {
    longitude = in.readDouble();
    latitude = in.readDouble();
    altitude = in.readDouble();
  }

  public double getLongitude() {
    return longitude;
  }

  public void setLongitude(double longitude) {
    this.longitude = longitude;
  }

  public double getLatitude() {
    return latitude;
  }

  public void setLatitude(double latitude) {
    this.latitude = latitude;
  }

  public double getAltitude() {
    return altitude;
  }

  public void setAltitude(double altitude) {
    this.altitude = altitude;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#equals(java.lang.Object)
   */
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    Coordinate other = (Coordinate) obj;
    if (Double.doubleToLongBits(altitude) != Double
        .doubleToLongBits(other.altitude))
      return false;
    if (Double.doubleToLongBits(latitude) != Double
        .doubleToLongBits(other.latitude))
      return false;
    if (Double.doubleToLongBits(longitude) != Double
        .doubleToLongBits(other.longitude))
      return false;
    return true;
  }

  /*
   * (non-Javadoc)
   * 
   * @see android.os.Parcelable#describeContents()
   */
  @Override
  public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
  }

  /*
   * (non-Javadoc)
   * 
   * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
   */
  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeDouble(longitude);
    dest.writeDouble(latitude);
    dest.writeDouble(altitude);
  }

  /**
     * Returns a Location with coordinates of the Coordinate object.
     * Other data such as velocity is read from another Location object.
   * 
   * @param coordinate
   *            the Coordinate 
   * @param location
   *            the base Location object
   * @return Location updates with data from Coordinate
   */
  public static Location getLocation(Coordinate coordinate, Location location) {
    Location newLoc = new Location(location);
    newLoc.setLatitude(coordinate.getLatitude());
    newLoc.setLongitude(coordinate.getLongitude());
    newLoc.setAltitude(coordinate.getAltitude());
    return newLoc;
  }

  /**
     * Returns a Location with coordinates of the Coordinate object.
   * 
   * @param coordinate
   *            the Coordinate 
   * @return Location with data from Coordinate
   */
  public static Location getLocation(Coordinate coordinate) {
    Location newLoc = new Location("GPS");
    newLoc.setLatitude(coordinate.getLatitude());
    newLoc.setLongitude(coordinate.getLongitude());
    newLoc.setAltitude(coordinate.getAltitude());
    return newLoc;
  }

  /**
   * Creates a Coordinate Object from a Location object
   * 
   * @param location
   *            the Location
   * @return the Coordinate
   */
  public static Coordinate getCoordinate(Location location) {
    Coordinate coordinate = new Coordinate(location.getLongitude(),
        location.getLatitude(), location.getAltitude());
    return coordinate;
  }

}




Java Source Code List

android.locationprivacy.algorithm.GeoReverseGeo.java
android.locationprivacy.algorithm.RadiusDistance.java
android.locationprivacy.control.CryptoDatabase.java
android.locationprivacy.control.LocationPrivacyManager.java
android.locationprivacy.model.AbstractLocationPrivacyAlgorithm.java
android.locationprivacy.model.Coordinate.java
android.locationprivacy.model.LocationPrivacyAlgorithmValues.java
android.locationprivacy.model.LocationPrivacyApplication.java
com.android.server.LocationManagerService.java
com.android.settings.Settings.java
com.android.settings.locationprivacy.LPPresetConfigAdapter.java
com.android.settings.locationprivacy.LocationPrivacyAdvancedSettings.java
com.android.settings.locationprivacy.LocationPrivacyAppPreference.java
com.android.settings.locationprivacy.LocationPrivacyDialog.java
com.android.settings.locationprivacy.LocationPrivacyMap.java
com.android.settings.locationprivacy.LocationPrivacyOfflineObfuscation.java
com.android.settings.locationprivacy.LocationPrivacyOnlineInfoActivity.java
com.android.settings.locationprivacy.LocationPrivacySettings.java
com.android.settings.locationprivacy.LocationPrivacyStatisticOverview.java
com.android.settings.locationprivacy.LocationPrivacyStatistic.java
com.android.settings.locationprivacy.SendDataService.java
com.android.settings.locationprivacy.StatisticDiagram24HPreference.java
com.android.settings.locationprivacy.StatisticDiagramPreference.java
com.android.settings.locationprivacy.UserRecoverableAuth.java
com.cyanogenmod.trebuchet.Launcher.java
com.jjoe64.graphview.BarGraphView.java
com.jjoe64.graphview.CustomLabelFormatter.java
com.jjoe64.graphview.GraphViewDataInterface.java
com.jjoe64.graphview.GraphViewSeries.java
com.jjoe64.graphview.GraphViewStyle.java
com.jjoe64.graphview.GraphView.java
com.jjoe64.graphview.LineGraphView.java
com.jjoe64.graphview.StatisticGraphView.java
com.jjoe64.graphview.ValueDependentColor.java
com.jjoe64.graphview.compatible.RealScaleGestureDetector.java
com.jjoe64.graphview.compatible.ScaleGestureDetector.java