public class Location extends Object
Information about the geographic location includes the latitude, longitude, moving speed, moving direction, and timestamp.
SequenceableSystemCapability.Location#LOCATION| 构造器 | 说明 |
|---|---|
Location(double latitude,
double longitude) |
Creates a new
Location object based on the specified longitude and latitude. |
Location(Location location) |
Creates a new
Location object based on an original object. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static float |
calculateBearing(double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude) |
Estimates the azimuth between two longitude and latitude coordinates.
|
static float |
calculateDistance(double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude) |
Estimates the linear distance between two longitude and latitude coordinates, in unit of meters.
|
float |
getAccuracy() |
Obtains the predicted horizontal accuracy of the device at the current location, in unit of meters.
|
PacMap |
getAdditions() |
Obtains extended information about a
Location object. |
double |
getAltitude() |
Obtains the altitude of the current location.
|
double |
getDirection() |
Obtains the moving direction of the device at the current location, in unit of degrees.
|
double |
getLatitude() |
Obtains the latitude of the device at the current location, in unit of degrees.
|
double |
getLongitude() |
Obtains the longitude of the device at the current location, in unit of degrees.
|
float |
getSpeed() |
Obtains the estimated moving speed of the device at the current location, in unit of meters/second.
|
long |
getTimeSinceBoot() |
Obtains the actual time when the location is obtained, in unit of nanoseconds.
|
long |
getTimeStamp() |
Obtains the actual timestamp when the location is obtained, in unit of milliseconds.
|
boolean |
marshalling(Parcel out) |
Marshalls a
Location object into a parcel. |
void |
setAccuracy(float value) |
Sets the horizontal accuracy of the device at the current location, in unit of meters.
|
void |
setAdditions(PacMap additions) |
Sets extended information about a
Location object. |
void |
setAltitude(double value) |
Sets the altitude, in unit of meters.
|
void |
setDirection(double value) |
Sets the moving direction of the device at the current location, in unit of degrees.
|
void |
setLatitude(double value) |
Sets the latitude, in unit of degrees.
|
void |
setLongitude(double value) |
Sets the longitude, in unit of degrees.
|
void |
setSpeed(float value) |
Sets the moving speed, in unit of meters/second.
|
void |
setTimeSinceBoot(long value) |
Sets the actual time when the location is obtained, in unit of nanoseconds.
|
void |
setTimeStamp(long value) |
Sets the actual timestamp when the location is obtained, in unit of milliseconds.
|
String |
toString() |
Returns a string representation of this
Location object. |
boolean |
unmarshalling(Parcel in) |
Unmarshalls a
Location object and updates its data. |
public Location(Location location) throws IllegalArgumentException
Location object based on an original object.location - Specifies the original Location object. The value cannot be null.IllegalArgumentException - Throws this exception if the value of the Location object is null.public Location(double latitude,
double longitude)
throws IllegalArgumentException
Location object based on the specified longitude and latitude.
Except the longitude and latitude, use default value 0 for remaining data fields, including the accuracy, altitude, moving speed, moving direction, and timestamp.
latitude - Specifies the latitude. The value range is [-90,90], in unit of degrees.longitude - Specifies the longitude. The value range is [-180,180], in unit of degrees.IllegalArgumentException - Throws this exception if the latitude is not within the range [-90, 90].IllegalArgumentException - Throws this exception if the longitude is not within the range [-180,180].public static float calculateBearing(double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude)
throws IllegalArgumentException
startLatitude - Indicates the latitude of the start position. The value range is [-90,90].startLongitude - Indicates the longitude of the start position. The value range is [-180,180].endLatitude - Indicates the latitude of the end position. The value range is [-90,90].endLongitude - Indicates the longitude of the end position. The value range is [-180,180].IllegalArgumentException - Throws this exception if the latitude is out of range [-90,90]
or the longitude is out of range [-180,180].public static float calculateDistance(double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude)
throws IllegalArgumentException
startLatitude - Specifies the latitude of the start point. The value range is [-90,90],
in unit of degrees.startLongitude - Specifies the longitude of the start point. The value range is [-180180],
in unit of degrees.endLatitude - Specifies the latitude of the end point. The value range is [-90,90],
in unit of degrees.endLongitude - Specifies the longitude of the end point. The value range is [-180,180],
in unit of degrees.IllegalArgumentException - Throws this exception if the latitude is not within the range [-90,90].IllegalArgumentException - Throws this exception if the longitude is not within the range [-180,180].public PacMap getAdditions()
Location object.
The extended information is stored in PacMap.
Location object. The value is null if no valid data exists.PacMappublic void setAdditions(PacMap additions)
Location object.public double getDirection()
The moving direction indicates the azimuth for horizontal movement of the device at the current position.
0.0 indicates no valid azimuth data.public void setDirection(double value)
throws IllegalArgumentException
The moving direction indicates the azimuth for horizontal movement of the device at the current position.
value - Specifies the azimuth for horizontal movement of the device. The value range is [0.0,360.0).IllegalArgumentException - Throws this exception if the azimuth for horizontal movement is not within
the range [0.0,360.0).public void setTimeSinceBoot(long value)
The time is a relative value compared with the time when the device is switched on.
value - Specifies the time when the location is obtained. The value must be greater than 0.0.
The default value 0.0 indicates no valid time data.public long getTimeSinceBoot()
The time obtained using Locator indicates the difference between the time when
the Location object is generated and the time when the device is switched on.
Location object is generated and the time
when the device is switched on. The value must be greater than or equal to 0. The default value 0
indicates that no valid time data.public double getLatitude()
The latitude obtained using Locator is based on the WGS 84 reference ellipsoid.
0.0 indicates no valid latitude data.public void setLatitude(double value)
throws IllegalArgumentException
value - Specifies the latitude. The value range is [-90.0,90.0].IllegalArgumentException - Throws this exception if the latitude is not within the range [-90.0,90.0].public double getLongitude()
The longitude obtained using Locator is based on the WGS 84 reference ellipsoid.
0.0 indicates no valid longitude data.public void setLongitude(double value)
throws IllegalArgumentException
value - Specifies the longitude. The value range is [-180.0, 180.0].IllegalArgumentException - Throws this exception if the latitude is not within the range [-180.0, 180.0].public double getAltitude()
public void setAltitude(double value)
value - Specifies the altitude.public float getAccuracy()
Assume that the predicted horizontal accuracy is equal to a radius of 68% probability. If you draw a circle with this radius centering at the latitude and longitude coordinate of the device, there will be a 68% probability that the actual location is within the circle.
0.0.
The default value 0.0 indicates no valid accuracy data.public void setAccuracy(float value)
Assume that the predicted horizontal accuracy is equal to a radius of 68% probability. If you draw a circle with this radius centering at the latitude and longitude coordinate of the device, there will be a 68% probability that the actual location is within the circle.
value - Specifies the horizontal accuracy. The value must be greater than or equal to 0.0.
The default value 0.0 indicates no valid accuracy data.public float getSpeed()
The moving speed is estimated with the ground as the reference.
0.0.
The default value 0.0 indicates that no moving speed data is available for the current location or that
the device is static.public void setSpeed(float value)
value - Specifies the moving speed of the device. The value must be greater than or equal to 0.0.
The default value 0.0 indicates no valid moving speed data.public long getTimeStamp()
The timestamp obtained using Locator indicates the Unix time
(a relative time since January 1, 1970) when the Location object is generated.
0. The default value 0 indicates that no valid timestamp.public void setTimeStamp(long value)
The timestamp is a relative time since January 1, 1970.
value - Specifies the timestamp when the location is obtained. The value must be greater than 0.0.
The default value 0.0 indicates no valid timestamp.public boolean unmarshalling(Parcel in)
Location object and updates its data.
Unmarshalling of Location objects is implemented using Sequenceable.
in - Specifies the Parcel object for unmarshalling a GeoAddress object.
The value must not be null.true if unmarshaling is successful; returns false otherwise.Parcel,
Sequenceablepublic boolean marshalling(Parcel out)
Location object into a parcel.
Marshalling of Location objects is implemented using Sequenceable.
out - Specifies the Parcel object for marshalling a Location object.
The value cannot be null.true if marshaling is successful; returns false otherwise.Parcel,
Sequenceable