QGeoCoordinate

Since: 1.0

#include <QtLocationSubset/QGeoCoordinate>

The QGeoCoordinate class defines a geographical position on the surface of the Earth.

A QGeoCoordinate is defined by latitude, longitude, and optionally, altitude.

Use type() to determine whether a coordinate is a 2D coordinate (has latitude and longitude only) or 3D coordinate (has latitude, longitude and altitude). Use distanceTo() and azimuthTo() to calculate the distance and bearing between coordinates.

The coordinate values should be specified using the WGS84 datum.


Overview

Public Functions Index

QGeoCoordinate ()
QGeoCoordinate (double latitude, double longitude)
QGeoCoordinate (double latitude, double longitude, double altitude)
QGeoCoordinate (const QGeoCoordinate &other)
~QGeoCoordinate ()
doublealtitude () const
QGeoCoordinateatDistanceAndAzimuth (qreal distance, qreal azimuth, qreal distanceUp=0.0) const
qrealazimuthTo (const QGeoCoordinate &other) const
qrealdistanceTo (const QGeoCoordinate &other) const
boolisValid () const
doublelatitude () const
doublelongitude () const
booloperator!= (const QGeoCoordinate &other) const
QGeoCoordinate &operator= (const QGeoCoordinate &other)
booloperator== (const QGeoCoordinate &other) const
voidsetAltitude (double altitude)
voidsetLatitude (double latitude)
voidsetLongitude (double longitude)
QStringtoString (CoordinateFormat format=DegreesMinutesSecondsWithHemisphere) const
CoordinateTypetype () const

Public Types

CoordinateFormat

Defines the possible formatting options for toString().

See also:

toString()

Degrees
DegreesWithHemisphere
DegreesMinutes
DegreesMinutesWithHemisphere
DegreesMinutesSeconds
DegreesMinutesSecondsWithHemisphere

CoordinateType

Defines the types of a coordinate.

InvalidCoordinate An invalid coordinate. A coordinate is invalid if its latitude or longitude values are invalid. Coordinate2D A coordinate with valid latitude and longitude values. Coordinate3D A coordinate with valid latitude and longitude values, and also an altitude value.

InvalidCoordinate
Coordinate2D
Coordinate3D

Public Functions

QGeoCoordinate ()

Constructs a coordinate.

The coordinate will be invalid until setLatitude() and setLongitude() have been called.

QGeoCoordinate (
  • doublelatitude,
  • doublelongitude )

Constructs a coordinate with the given latitude and longitude.

If the latitude is not between -90 to 90 inclusive, or the longitude is not between -180 to 180 inclusive, none of the values are set and the type() will be QGeoCoordinate::InvalidCoordinate.

See also:

isValid()

QGeoCoordinate (
  • doublelatitude,
  • doublelongitude,
  • doublealtitude )

Constructs a coordinate with the given latitude, longitude and altitude.

If the latitude is not between -90 to 90 inclusive, or the longitude is not between -180 to 180 inclusive, none of the values are set and the type() will be QGeoCoordinate::InvalidCoordinate.

Note that altitude specifies the metres above sea level.

See also:

isValid()

QGeoCoordinate (

Constructs a coordinate from the contents of other.

~QGeoCoordinate ()

Destructor.

double altitude ()

Returns the altitude (meters above sea level).

The return value is undefined if the altitude has not been set.

See also:

setAltitude(), type()

QGeoCoordinate atDistanceAndAzimuth (
  • qrealdistance,
  • qrealazimuth,
  • qrealdistanceUp )

Returns the coordinate that is reached by traveling distance meters from the current coordinate at azimuth (or bearing) along a great-circle.

There is an assumption that the Earth is spherical for the purpose of this calculation.

The altitude will have distanceUp added to it.

Returns an invalid coordinate if this coordinate is invalid.

qreal azimuthTo (

Returns the azimuth (or bearing) in degrees from this coordinate to the coordinate specified by other.

Altitude is not used in the calculation.

The bearing returned is the bearing from the origin to other along the great-circle between the two coordinates. There is an assumption that the Earth is spherical for the purpose of this calculation.

Returns 0 if the type of this coordinate or the type of other is QGeoCoordinate::InvalidCoordinate.

qreal distanceTo (

Returns the distance (in meters) from this coordinate to the coordinate specified by other.

Altitude is not used in the calculation.

This calculation returns the great-circle distance between the two coordinates, with an assumption that the Earth is spherical for the purpose of this calculation.

Returns 0 if the type of this coordinate or the type of other is QGeoCoordinate::InvalidCoordinate.

bool isValid ()

Returns true if the type() is Coordinate2D or Coordinate3D.

double latitude ()

Returns the latitude, in decimal degrees.

The return value is undefined if the latitude has not been set.

A positive latitude indicates the Northern Hemisphere, and a negative latitude indicates the Southern Hemisphere.

See also:

setLatitude(), type()

double longitude ()

Returns the longitude, in decimal degrees.

The return value is undefined if the longitude has not been set.

A positive longitude indicates the Eastern Hemisphere, and a negative longitude indicates the Western Hemisphere.

bool operator!= (

Returns true if the latitude, longitude or altitude of this coordinate are not the same as those of other.

QGeoCoordinate & operator= (

Assigns other to this coordinate and returns a reference to this coordinate.

bool operator== (

Returns true if the latitude, longitude and altitude of this coordinate are the same as those of other.

The longitude will be ignored if the latitude is +/- 90 degrees.

void setAltitude (
  • doublealtitude)

Sets the altitude (meters above sea level) to altitude.

See also:

altitude()

void setLatitude (
  • doublelatitude)

Sets the latitude (in decimal degrees) to latitude.

The value should be in the WGS84 datum.

To be valid, the latitude must be between -90 to 90 inclusive.

See also:

latitude()

void setLongitude (
  • doublelongitude)

Sets the longitude (in decimal degrees) to longitude.

The value should be in the WGS84 datum.

To be valid, the longitude must be between -180 to 180 inclusive.

See also:

longitude()

QString toString (

Returns this coordinate as a string in the specified format.

For example, if this coordinate has a latitude of -27.46758, a longitude of 153.027892 and an altitude of 28.1, these are the strings returned depending on format:

format value Returned string Degrees -27.46758{0xB0}, 153.02789{0xB0}, 28.1m DegreesWithHemisphere 27.46758{0xB0} S, 153.02789{0xB0} E, 28.1m DegreesMinutes -27{0xB0} 28.054', 153{0xB0} 1.673', 28.1m DegreesMinutesWithHemisphere 27{0xB0} 28.054 S', 153{0xB0} 1.673' E, 28.1m DegreesMinutesSeconds -27{0xB0} 28' 3.2", 153\unicode{0xB0} 1' 40.4", 28.1m DegreesMinutesSecondsWithHemisphere 27{0xB0} 28' 3.2" S, 153\unicode{0xB0} 1' 40.4" E, 28.1m

The altitude field is omitted if no altitude is set.

If the coordinate is invalid, an empty string is returned.

CoordinateType type ()

Returns the type of this coordinate.

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus