List of usage examples for android.location Location Location
public Location(Location l)
From source file:Main.java
public static Location getLocation() { Location targetLocation = new Location("");//provider name is unecessary targetLocation.setLatitude(32.8206645d);//your coords of course targetLocation.setLongitude(-96.7313396d); return targetLocation; }
From source file:Main.java
public static double getDistance(double x1, double y1, double x2, double y2) { Location l1 = new Location("loc1"); l1.setLatitude(y1);/*from w ww. j av a 2 s .co m*/ l1.setLongitude(x1); Location l2 = new Location("loc2"); l2.setLatitude(y2); l2.setLongitude(x2); return l1.distanceTo(l2); }
From source file:Main.java
public static double getDistance(double lat1, double lng1, double lat2, double lng2) { Location locationA = new Location("point A"); locationA.setLatitude(lat1);/*from w w w .j av a2s. c o m*/ locationA.setLongitude(lng1); Location locationB = new Location("point B"); locationB.setLatitude(lat2); locationB.setLongitude(lng2); double distance = locationA.distanceTo(locationB); return distance; }
From source file:Main.java
public static Location convertToLocation(double longitude, double latitude) { Location location = new Location(""); location.setLongitude(longitude);//from w w w . ja v a 2s .c o m location.setLatitude(latitude); return location; }
From source file:Main.java
public static double getCalculatedDistance(double startLatitude, double startLongitude, double targetLatitude, double targetLongitude) { Location startLocation = new Location("Start Location"); startLocation.setLatitude(startLatitude); startLocation.setLongitude(startLongitude); Location targetLocation = new Location("Target Location"); targetLocation.setLatitude(targetLatitude); targetLocation.setLongitude(targetLongitude); float distance = startLocation.distanceTo(targetLocation); double tempDistanceInMiles = distance * 0.000621371192; return tempDistanceInMiles; }
From source file:Main.java
/** * Will return a list of random location from the given position & radius * @param amount/* w ww . j a v a2 s . com*/ * @param lat * @param lng * @param radius * @return ArrayList<Location> */ public static ArrayList<Location> randomLocations(int amount, double lat, double lng, double radius) { ArrayList<Location> locations = new ArrayList<Location>(0); Location centerLocation = new Location("local"); centerLocation.setLatitude(lat); centerLocation.setLongitude(lng); final double lngScale = Math.cos((Math.PI / 180.0) * lat); final double radiusDeg = radius / 111.2; // radius converted to degrees (square) while (locations.size() < amount) { Location l = new Location("local"); double dLat = (Math.random() * radiusDeg * 2) - radiusDeg; double dLng = (Math.random() * radiusDeg * 2 / lngScale) - (radiusDeg / lngScale); l.setLatitude(centerLocation.getLatitude() + dLat); l.setLongitude(centerLocation.getLongitude() + dLng); double dist = l.distanceTo(centerLocation) / 1000.0; if (dist < (radius)) { locations.add(l); } } return locations; }
From source file:Main.java
public static Location createLocation(final double latitude, final double longitude, final float accuracy) { Location location = new Location("TestProvider"); location.setLatitude(latitude);//from w w w. j a v a2s . co m location.setLongitude(longitude); location.setAccuracy(accuracy); return location; }
From source file:Main.java
public static Location getLocation(Address addr) { Location location = new Location(LocationManager.NETWORK_PROVIDER); location.setLatitude(addr.getLatitude()); location.setLongitude(addr.getLongitude()); return location; }
From source file:Main.java
public static Location readLocation(Parcel in) { Location loc = new Location(in.readString()); loc.setTime(in.readLong());/*from w ww . j av a 2s . c om*/ loc.setLatitude(in.readDouble()); loc.setLongitude(in.readDouble()); loc.setAltitude(in.readDouble()); loc.setAccuracy(in.readFloat()); loc.setBearing(in.readFloat()); loc.setSpeed(in.readFloat()); return loc; }
From source file:Main.java
/** * This method returns the last,best known current location for user * @param context//from w w w.j a v a2s . com * @return */ public static Location getLastBestLocation(Context context) { // get location providers LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Location locationGPS = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location locationNet = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // check which ones are available boolean haveGPS = (locationGPS != null); boolean haveNet = (locationNet != null); if (!haveGPS && !haveNet) { // no providers available String msg = "Could not find a location. Using random location now."; displayAlert(context, msg); Location l = new Location("yum fake location"); l.setLatitude(45.0); l.setLongitude(45.0); // uh oh... no location return new Location(l); } else if (haveGPS && !haveNet) { // only gps available return locationGPS; } else if (!haveGPS && haveNet) { // only cell location available return locationNet; } else { // choose the most recent one long GPSLocationTime = locationGPS.getTime(); long NetLocationTime = locationNet.getTime(); if (GPSLocationTime - NetLocationTime > 0) { return locationGPS; } else { return locationNet; } } }