Positioning
定位
The Positioning component of the Qt Location API is about the geographical position, size, and address of some place. Positioning contains a QGeoCoordinate class, containing latitude, longitude and altitude in meters. QGeoLocation contains a QGeoCoordinate plus address and size information (a bounding box) so that positions can be more than mathematical points. Movement into or out of the defined bounding box areas can be monitored. The API also allows the developer to control the source of the positional information as well.
Qt定位API的定位组件与某个地方的地理位置、大小和地址有关。定位包含一个QGeoCoordinate类,包含以米为单位的纬度、经度和高度。QGeoLocation包含QGeoCoordinate加上地址和大小信息(一个边界框),因此位置可以超过数学点。可以监控进入或离开定义的边界框区域的移动。API还允许开发人员控制位置信息的来源。
Location data involves a precisely specified position on the Earth's surface — as provided by a latitude-longitude coordinate — along with associated data, such as:
位置数据涉及地球表面上精确指定的位置(由经纬度坐标提供)以及相关数据,例如:
The date and time at which the position was reported
报告职位的日期和时间
The velocity of the device that reported the position
报告位置的设备的速度
The altitude of the reported position (height above sea level)
报告位置的高度(海拔高度)
The bearing of the device in degrees, relative to true north
装置相对于正北的方位,以度为单位
This data can be extracted through a variety of methods. One of the most well known methods of positioning is GPS (Global Positioning System), a publicly available system that uses radiowave signals received from Earth-orbiting satellites to calculate the precise position and time of the receiver. Another popular method is 'Cell Identifier Positioning', which uses the cell identifier of the cell site that is currently serving the receiving device to calculate its approximate location. These and other positioning methods can all be used with the Location API; the only requirement for a location data source within the API is that it provides a latitude-longitude coordinate with a date/time value, with the option of providing the other attributes listed above.
可以通过多种方法提取这些数据。最著名的定位方法之一是GPS(全球定位系统),这是一种公开可用的系统,使用从地球轨道卫星接收的无线电波信号来计算接收器的精确位置和时间。另一种流行的方法是“小区标识符定位”,它使用当前为接收设备服务的小区站点的小区标识符来计算其近似位置。这些和其他定位方法都可以与定位API一起使用;API中位置数据源的唯一要求是提供带有日期/时间值的经纬度坐标,并可以选择提供上面列出的其他属性。
Location data sources are created by subclassing QGeoPositionInfoSource and providing QGeoPositionInfo objects through the QGeoPositionInfoSource::positionUpdated() signal. Clients that require location data can connect to the positionUpdated() signal and call startUpdates() or requestUpdate() to trigger the distribution of location data. The location data distribution can be stopped by calling the stopUpdates() function.
位置数据源是通过子类化QGeoPositionInfo源并通过QGeoppositionInfocf对象的QGeoPositionInfoSource::positionUpdated()信号来创建的。需要位置数据的客户端可以连接到positionUpdated()信号,并调用startUpdates()或requestUpdate()来触发位置数据的分发。可以通过调用stopUpdates()函数来停止位置数据分发。
A default position source may be available on some platforms. Call QGeoPositionInfoSource::createDefaultSource() to create an instance of the default position source. The method returns nullptr if no default source is available for the platform.
If a problem occurs with access to the information source then an errorOccurred() signal is emitted.
某些平台上可能提供默认位置源。调用QGeoPositionInfoSource::createDefaultSource() 以创建默认位置源的实例。如果平台没有可用的默认源,则该方法返回nullptr。
如果访问信息源时出现问题,则会发出errorOccurred()信号
The QGeoAreaMonitorSource class enables client applications to be notified when the receiving device has moved into or out of a particular area, as specified by a coordinate and radius. If the platform provides built-in support for area monitoring, the QGeoAreaMonitorSource::createDefaultSource() method returns an instance of the default area monitor.
QGeoAreaMonitorSource类允许在接收设备移入或移出由坐标和半径指定的特定区域时通知客户端应用程序。如果平台提供了对区域监视的内置支持,那么QGeoAreaMonitorSource::createDefaultSource()方法将返回默认区域监视器的实例。
Satellite information can also be distributed through the QGeoSatelliteInfoSource class. Call QGeoSatelliteInfoSource::createDefaultSource() to create an instance of the default satellite data source for the platform if one is available. Alternatively, clients can subclass it to provide a custom satellite data source.
卫星信息也可以通过QGeoSatelliteInfoSource类分发。调用QGeoSatelliteInfoSource::createDefaultSource()为平台创建默认卫星数据源的实例(如果可用)。或者,客户端可以将其子类化,以提供自定义卫星数据源。
Requesting Location Data from Data Sources
从数据源请求位置数据以从源接收数据
To receive data from a source, connect to its positionUpdated() signal, then call either startUpdates() or requestUpdate() to begin.
Here is an example of a client that receives data from the default location data source, as returned by QGeoPositionInfoSource::createDefaultSource():
连接到其positionUpdated()信号,然后调用startUpdates()或requestUpdate()开始。
下面是一个从默认位置数据源接收数据的客户端示例,由QGeoPositionInfoSource::createDefaultSource()返回:
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(QObject *parent = 0)
: QObject(parent)
{
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this);
if (source) {
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
source->startUpdates();
}
}
private slots:
void positionUpdated(const QGeoPositionInfo &info)
{
qDebug() << "Position updated:" << info;
}
};
Controlling Aspects of Data Sources
控制数据源的各个方面
The QGeoPositionInfoSource::setUpdateInterval() method can be used to control the rate at which position updates are received. For example, if the client application only requires updates once every 30 seconds, it can call setUpdateInterval(30000). If no update interval is set, or setUpdateInterval() is called with a value of 0, the source uses a default interval or some other internal logic to determine when updates should be provided.
QGeoPositionInfoSource::setUpdateInterval()方法可用于控制接收位置更新的速率。例如,如果客户端应用程序只需要每30秒更新一次,则可以调用setUpdateInterval(30000)。如果未设置更新间隔,或使用值0调用setUpdateInterval(),则源将使用默认间隔或其他一些内部逻辑来确定何时应提供更新。
QGeoPositionInfoSource::setPreferredPositioningMethods() enables client applications to request that a certain type of positioning method be used. For example, if the application prefers to use only satellite positioning, which offers fairly precise outdoor positioning but can be a heavy user of power resources, it can call this method with the QGeoPositionInfoSource::SatellitePositioningMethods value. However, this method should only be used in specialized client applications; in most cases, the default positioning methods should not be changed, as a source may internally use a variety of positioning methods that can be useful to the application.
QGeoPositionInfoSource::setPreferredPositioningMethods()允许客户端应用程序请求使用某种类型的定位方法。例如,如果应用程序只喜欢使用卫星定位,它提供了相当精确的室外定位,但可能会大量使用电力资源,则可以使用QGeoPositionInfoSource::SatellitePositioningMethods值调用此方法。然而,这种方法只能用于专门的客户端应用程序;在大多数情况下,不应更改默认定位方法,因为源可能在内部使用对应用程序有用的各种定位方法。
NMEA Data
NMEA数据
NMEA is a common text-based protocol for specifying navigational data. For convenience, the QNmeaPositionInfoSource is provided to enable client applications to read and distribute NMEA data in either real-time mode (for example, when streaming from a GPS device) or simulation mode (for example, when reading from a NMEA log file). In simulation mode, the source will emit updates according to the time stamp of each NMEA sentence to produce a "replay" of the recorded data.
NMEA是一种通用的基于文本的协议,用于指定导航数据。为了方便起见,提供了QNmeaPositionInfoSource,以使客户端应用程序能够以实时模式(例如,当从GPS设备流式传输时)或模拟模式(例如当从NMEA日志文件读取时)读取和分发NMEA数据。在模拟模式下,信源将根据每个NMEA句子的时间戳发出更新,以生成记录数据的“重播”。
Generally, the capabilities provided by the default position source as returned by QGeoPositionInfoSource::createDefaultSource(), along with the QNmeaPositionInfoSource class, are sufficient for retrieving location data. However, in some cases developers may wish to write their own custom location data source.
通常,QGeoPositionInfoSource::createDefaultSource()返回的默认位置源提供的功能以及QNmeaPositionInfoSource类足以检索位置数据。然而,在某些情况下,开发人员可能希望编写自己的自定义位置数据源。
The Log File Position Source (C++) example demonstrates how to subclass QGeoPositionInfoSource to create a custom positioning source.
日志文件位置源(C++)示例演示了如何将QGeoPositionInfoSource子类化以创建自定义定位源。
Examples
示例
Flickr Example
Flickr示例
The Flickr Example uses the current location to download thumbnail images from Flickr relevant to the current location.
Flickr示例使用当前位置从Flickr下载与当前位置相关的缩略图。