Android Open Source - sigimera-android-app Distance Controller






From Project

Back to project page sigimera-android-app.

License

The source code is released under:

GNU General Public License

If you think the Android project sigimera-android-app 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 org.sigimera.app.android.controller;
//from  w  w  w  .j av a2  s  .co m
import java.math.BigDecimal;

import org.sigimera.app.android.model.Crisis;

import android.location.Location;

public abstract class DistanceController {
  private static int decimalPlaces = 2;

  /**
   * 
   * @param _nearCrisis
   * @param _userLocation
   * @return
   */
  public static double getNearCrisisDistance(Crisis _nearCrisis, Location _userLocation) {
    if ( _nearCrisis != null && _userLocation != null ) {
      return computeDistance(
          _userLocation.getLatitude(), _userLocation.getLongitude(), 
          _nearCrisis.getLatitude(), _nearCrisis.getLongitude());
    }
    return -1;
  }

  /**
   * Compute the distance between two GPS locations based on Vincenty Formula.
   * 
   * @param lat1
   * @param long1
   * @param lat2
   * @param long2
   * @return
   */
  public static double computeDistance(double lat1, double long1,
      double lat2, double long2) {
    double earthRadius = 6371;
    double dLatBot = Math.toRadians(lat2 - lat1);
    double dLonBot = Math.toRadians(long2 - long1);
    double a = Math.sin(dLatBot / 2) * Math.sin(dLatBot / 2)
        + Math.cos(Math.toRadians(lat1))
        * Math.cos(Math.toRadians(lat2)) * Math.sin(dLonBot / 2)
        * Math.sin(dLonBot / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double distance = earthRadius * c;

    BigDecimal bigD = new BigDecimal(distance);
    bigD = bigD.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);

    return bigD.doubleValue();
  }
}




Java Source Code List

org.sigimera.app.android.CrisesListFragment.java
org.sigimera.app.android.CrisisActivity.java
org.sigimera.app.android.CrisisAlertActivity.java
org.sigimera.app.android.GCMIntentService.java
org.sigimera.app.android.LoginFragment.java
org.sigimera.app.android.MainActivity.java
org.sigimera.app.android.OfflineMode.java
org.sigimera.app.android.ProfileFragment.java
org.sigimera.app.android.StatisticFragment.java
org.sigimera.app.android.StatsFragment.java
org.sigimera.app.android.TabManager.java
org.sigimera.app.android.TabsAdapter.java
org.sigimera.app.android.ToastNotification.java
org.sigimera.app.android.backend.PersistentStorage.java
org.sigimera.app.android.backend.auth.AccountAuthenticator.java
org.sigimera.app.android.backend.auth.AuthenticationService.java
org.sigimera.app.android.backend.auth.AuthenticatorActivity.java
org.sigimera.app.android.backend.network.CrisesHttpHelper.java
org.sigimera.app.android.backend.network.LocationUpdaterHttpHelper.java
org.sigimera.app.android.backend.network.LoginHttpHelper.java
org.sigimera.app.android.backend.network.MyHttpClient.java
org.sigimera.app.android.backend.network.NearCrisesHttpHelper.java
org.sigimera.app.android.backend.network.SingleCrisisHttpHelper.java
org.sigimera.app.android.backend.network.StatisticCrisesHttpHelper.java
org.sigimera.app.android.backend.network.StatisticUsersHttpHelper.java
org.sigimera.app.android.controller.ApplicationController.java
org.sigimera.app.android.controller.DistanceController.java
org.sigimera.app.android.controller.LocationController.java
org.sigimera.app.android.controller.PersistanceController.java
org.sigimera.app.android.controller.SessionHandler.java
org.sigimera.app.android.exception.AuthenticationErrorException.java
org.sigimera.app.android.model.Constants.java
org.sigimera.app.android.model.CrisesStats.java
org.sigimera.app.android.model.Crisis.java
org.sigimera.app.android.model.UserSettings.java
org.sigimera.app.android.model.User.java
org.sigimera.app.android.model.UsersStats.java
org.sigimera.app.android.model.map.CollectionOverlay.java
org.sigimera.app.android.util.Common.java
org.sigimera.app.android.util.Config.java
org.sigimera.app.android.util.MD5Util.java