public class Location extends Object
Represents a position and possible velocity returned from positioning API's. This class is used both by foreground and background location for the purposes of both conveying the users location and conveying a desired location e.g. in the case of geofencing where we can define a location that would trigger the callback.
Trivial one time usage of location data can look like this sample:
You can also track location in the foreground using API calls like this:
The sample below demonstrates the usage of the background geofencing API:
Constructor and Description |
---|
Location() |
Location(double latitude,
double longitude) |
Location(double latitude,
double longitude,
double altitude,
float direction) |
Modifier and Type | Method and Description |
---|---|
Comparator<Location> |
createDistanceCompartor()
Creates a comparator for sorting locations in order of increasing distance from the current
location.
|
float |
getAccuracy()
Returns the horizontal accuracy of the location in meters
|
double |
getAltitude()
Returns the altitude of this Location
|
float |
getDirection()
Returns the direction of this Location in degress 0-360
|
double |
getDistanceTo(Location l2)
Gets the distance in metres from the current location to another location.
|
double |
getLatitude()
Returns the latitude of this Location
|
double |
getLongitude()
Returns the longitude of this Location
|
double |
getLongtitude()
Deprecated.
use getLongitude
|
int |
getStatus()
The status of the location one of: LocationManager.AVAILABLE,
LocationManager.OUT_OF_SERVICE or LocationManager.TEMPORARILY_UNAVAILABLE:
|
long |
getTimeStamp()
Returns the timestamp of this Location
|
float |
getVelocity()
Returns the velocity of this Location in meters per second (m/s)
|
void |
setAccuracy(float accuracy) |
void |
setAltitude(double altitude)
Sets the altitude of this Location
|
void |
setDirection(float direction)
Sets the direction of this Location
|
void |
setLatitude(double latitude)
Sets the latitude of this Location
|
void |
setLongitude(double longtitude)
Sets the longitude of this Location
|
void |
setLongtitude(double longtitude)
Deprecated.
use setLongitude
|
void |
setStatus(int status)
The status of the location one of: LocationProvider.AVAILABLE,
LocationProvider.OUT_OF_SERVICE or LocationProvider.TEMPORARILY_UNAVAILABLE:
|
void |
setTimeStamp(long timeStamp)
Sets the timeStamp of this Location
|
void |
setVelocity(float velocity)
Sets the velocity of this Location
|
String |
toString()
Returns a string representation of the object.
|
public Location()
public Location(double latitude, double longitude, double altitude, float direction)
public Location(double latitude, double longitude)
public float getAccuracy()
public double getAltitude()
public float getDirection()
public double getLatitude()
public double getLongitude()
public double getLongtitude()
public int getStatus()
public long getTimeStamp()
public float getVelocity()
public void setAccuracy(float accuracy)
public void setAltitude(double altitude)
altitude
- public void setDirection(float direction)
direction
- public void setLatitude(double latitude)
latitude
- public void setLongitude(double longtitude)
longitude
- public void setLongtitude(double longtitude)
longitude
- public void setStatus(int status)
public void setTimeStamp(long timeStamp)
timeStamp
- public void setVelocity(float velocity)
velocity
- public double getDistanceTo(Location l2)
l2
- The location to measure distance to.public String toString()
public Comparator<Location> createDistanceCompartor()