List of usage examples for android.location Location getLatitude
public double getLatitude()
From source file:Main.java
public static String locationToString(Location location) { return "(" + location.getLatitude() + ";" + location.getLongitude() + ")" + " S=" + location.getSpeed() + " C=" + location.getBearing() + " A=" + location.getAccuracy(); }
From source file:Main.java
public static String getString(Location location) { double lat = location.getLatitude(); double lon = location.getLongitude(); return lat + "," + lon; }
From source file:Main.java
public static boolean positionInChina(Location mLocation) { if (mLocation.getLatitude() > 18.167 && mLocation.getLatitude() < 53.55) { if (mLocation.getLongitude() > 73.667 && mLocation.getLongitude() < 135.033) { return true; }/* w ww .j ava 2 s . c o m*/ } return false; }
From source file:Main.java
public static void setVivaCurrentLocation(Context context, Location location) { try {/*from w w w. ja v a 2 s . c om*/ String loc = location.getLatitude() + "," + location.getLongitude(); getPreferences(context).edit().putString(Viva_Current_Location, loc).apply(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
/** * Computes the distance in kilometers between two points on Earth. * * @param p1 First point//from w ww. j ava2 s . co m * @param p2 Second point * @return Distance between the two points in kilometers. */ public static double distanceKm(Location p1, Location p2) { double lat1 = p1.getLatitude(); double lon1 = p1.getLongitude(); double lat2 = p2.getLatitude(); double lon2 = p2.getLongitude(); return distanceKm(lat1, lon1, lat2, lon2); }
From source file:Main.java
/** * Computes the distance in meters between two points on Earth. * * @param p1 First point//from www.ja v a 2 s .c o m * @param p2 Second point * @return Distance between the two points in meters. */ public static double distance(Location p1, Location p2) { double lat1 = p1.getLatitude(); double lon1 = p1.getLongitude(); double lat2 = p2.getLatitude(); double lon2 = p2.getLongitude(); return distance(lat1, lon1, lat2, lon2); }
From source file:Main.java
/** * Computes the bearing in radians between two points on Earth. * * @param p1 First point/* w ww . j av a 2 s . c om*/ * @param p2 Second point * @return Bearing between the two points in radians. A value of 0 means due * north. */ public static double bearingRad(Location p1, Location p2) { double lat1 = p1.getLatitude(); double lon1 = p1.getLongitude(); double lat2 = p2.getLatitude(); double lon2 = p2.getLongitude(); return bearingRad(lat1, lon1, lat2, lon2); }
From source file:Main.java
/** * Checks if a given location is a valid (i.e. physically possible) location * on Earth. Note: The special separator locations (which have latitude = * 100) will not qualify as valid. Neither will locations with lat=0 and lng=0 * as these are most likely "bad" measurements which often cause trouble. * //w w w . j a v a 2 s .co m * @param location the location to test * @return true if the location is a valid location. */ public static boolean isValidLocation(Location location) { return location != null && Math.abs(location.getLatitude()) <= 90 && Math.abs(location.getLongitude()) <= 180; }
From source file:Main.java
public static String getLocation(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); String provider = LocationManager.NETWORK_PROVIDER; Location location = locationManager.getLastKnownLocation(provider); return location.getLatitude() + ":" + location.getLongitude(); }
From source file:Main.java
/** * Returns declination in degrees at given location * //from www . j av a 2 s . c o m * @param location * @return Declination in degrees */ public static float getDeclinationAt(Location location) { return getDeclinationAt((float) location.getLatitude(), (float) location.getLongitude(), (float) location.getAltitude()); }