List of usage examples for android.location Location setLatitude
public void setLatitude(double latitude)
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); l1.setLongitude(x1);//from w w w .ja v a 2 s.co m 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); locationA.setLongitude(lng1);/*w w w . ja v a 2s.com*/ 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 createLocation(final double latitude, final double longitude, final float accuracy) { Location location = new Location("TestProvider"); location.setLatitude(latitude); location.setLongitude(longitude);//w w w. j a v a2s . com location.setAccuracy(accuracy); return location; }
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 Location convertToLocation(double longitude, double latitude) { Location location = new Location(""); location.setLongitude(longitude);//w w w. ja v a2s.c om location.setLatitude(latitude); 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 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/*from ww w . j ava2 s . c o m*/ * @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
/** * Create a {@link Location} object from the speified latitude and longitude. * @param latitude the latitude for the location to create. * @param longitude the longitude for the location to create. * @return a {@link Location} object./* w ww. ja v a2s . c om*/ */ public static Location createLocation(double latitude, double longitude) { Location location = new Location(LocationManager.NETWORK_PROVIDER); location.setLatitude(latitude); location.setLongitude(longitude); location.setAccuracy(10f); location.setTime(System.currentTimeMillis()); location.setAltitude(0d); location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); return location; }
From source file:Main.java
public static Location readLocation(Parcel in) { Location loc = new Location(in.readString()); loc.setTime(in.readLong());//ww w .j a va 2 s .c o m 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; }