Example usage for android.location Location setLongitude

List of usage examples for android.location Location setLongitude

Introduction

In this page you can find the example usage for android.location Location setLongitude.

Prototype

public void setLongitude(double longitude) 

Source Link

Document

Set the longitude, in degrees.

Usage

From source file:Main.java

public static Location convertToLocation(double longitude, double latitude) {
    Location location = new Location("");
    location.setLongitude(longitude);
    location.setLatitude(latitude);/*from ww  w  . ja v  a2s  .co  m*/
    return location;
}

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  w w.j av  a  2s .c  o  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  .ja  va 2s .  c  om*/
    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 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 a2  s.  c  om*/
    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

/**
 * Will return a list of random location from the given position & radius
 * @param amount// ww w  .  j  a v  a 2  s  . c  om
 * @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 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

/**
 * 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.//from   ww w.  j a  v  a 2 s .  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 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 readLocation(Parcel in) {
    Location loc = new Location(in.readString());
    loc.setTime(in.readLong());/*from   w  w  w .  j a v a2 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;
}