Navigation

Views

Location framework provides a library called liblocation which is used for developing location aware applications in Fremantle. Liblocation supports internal GPS, network based methods and external bluetooth GPS.

Liblocation has two public GObjects. LocationGPSDControl is used for starting and stopping of location services, setting location method and interval, and listening for errors. LocationGPSDevice has information about device status and contains the actual fix when one exists. The two GObjects are initiated as follows:

Liblocation supports the following location methods which are defined in location-gpsd-control.h.

LOCATION_METHOD_USER_SELECTED: Liblocation will choose the best possible location method based on location settings in control panel. You can think of it as asking all the methods CWP+ACWP+GNSS+AGNSS. Choose this method if you don't have any special needs.

LOCATION_METHOD_CWP - Complementary Wireless Positioning: This method provides either coordinates for center of current country with horizontal accuracy equalling radius of the country (MCC fix), or coordinates based on currently used GSM base station. Latter is used if such information exists in device's cache, which is updated when ACWP method is used. SIM card is needed for CWP method.

LOCATION_METHOD_ACWP - Assisted Complementary Wireless Positioning: A method where device is located based on cellular base station to which device is registered to. SIM card and a network connection is needed for ACWP method. If no network connection is available, this equals to CWP. Application might receive MCC fixes before base station information from external location server is fetched and as a fallback if e.g. network is temporary unavailable.

LOCATION_METHOD_GNSS - Global Navigation Satellite System: A method for using GPS receiver. Typically time for the first fix is significantly longer than with AGNSS. Neither SIM card nor network connection is needed for GNSS method, and GNSS can even be used in offline mode.

LOCATION_METHOD_AGNSS - Assisted Global Navigation Satellite System. A method for using GPS receiver with assistance data from external location server. A SIM card and a network connection is needed for AGNSS method. If no network connection or SIM card is available, this equals to GNSS.

Location resources are shared between applications, and applications can request different location methods. Fixes for all requested methods are sent for all applications listening to liblocation changed signal, therefore application should judge whether fix it is receiving, is one that it needs. See LocationGPSDeviceFix section for discussion.

If device is set for bluetooth GPS from control panel, it can used for locationing via USER_SELECTED, AGNSS and GNSS methods. In this case AGNSS and GNSS do not differ, because assistance server cannot be utilized.

Device caches cell information for ACWP and satellite information for AGNSS. Hence if a non-assisted location method is used immediately after it's assisted counterpart, it will probably work as the assisted one.

Location method is set as LocationGPSDControl's preferred-method property. Several methods can be given by bitwise or'ing the method identifiers:

ACWP and AGNSS methods require network positioning and GNSS and AGNSS require GPS to be enabled in location settings. If requirements for asked methods are not enabled when starting location, user is prompted a dialog to enable them. After that all the possible preferred-methods are started. If there is not any, an error to application is signalled.

USER_SELECTED method makes exception to dialog rule. Albeit it uses all of the methods: CWP+ACWP+GNSS+AGNSS, dialog is shown only if both networking and gps are disabled.

If user changes location settings during location session, then used location method is modified to best available accordingly, and error signalled if none is available.

Here is table that summarizes differences between the methods. Accuracy refers to horizontal accuracy of the fix.

Liblocation supports a default interval (equals to one second) and intervals of 1, 2, 5, 10, 20, 30, 60 and 120 seconds between fixes. These are defined in location-gpsd-control.h. Due to performance and power consumption reasons, all the intervals provide fixes only if position of the device has changed. Therefore the interval reflects more how often device checks for coordinate changes, than the actual interval between fixes. Nature of GPS fixes being constantly changing guarantees that GPS fixes are provided with requested interval. However, if there are several applications using different intervals, then the used interval is the minimum of intervals requested by all applications.

Location interval is set as LocationGPSDControl's "preferred-interval" property:

LocationCellInfo *cell_info: Information about cell the device is connected to

The most useful field is naturally "fix" which contains position and movement of the device and accuracies for them. "LocationGPSDeviceFix" fields are listed in the table below. In "Fields Flag" column there is a identifier which can be bitwisely anded with "fields" field, to see whether corresponding field is set.

LocationGPSDeviceFix

Variable

Description

mode

Mode of the fix (2D, 3D, not seen or no fix)

fields

Bitfield representing what fields contain valid data

Variable

Unit

Description

Fields Flag

time

s

Timestamp of the update

LOCATION_GPS_DEVICE_TIME_SET

ept

s

Time accuracy

latitude

degrees

Fix latitude

LOCATION_GPS_DEVICE_LATLONG_SET

longitude

degrees

Fix longitude

LOCATION_GPS_DEVICE_LATLONG_SET

eph

cm

Horizontal position accuracy

altitude

m

Fix altitude

LOCATION_GPS_DEVICE_ALTITUDE_SET

epv

m

Altitude accuracy

track

degrees

Direction of motion

LOCATION_GPS_DEVICE_TRACK_SET

epd

degrees

Track accuracy

speed

km/h

Current speed

LOCATION_GPS_DEVICE_SPEED_SET

eps

km/h

Speed accuracy

climb

m/s

Current rate of climb

LOCATION_GPS_DEVICE_CLIMB_SET

epc

m/s

Climb accuracy

The units for epv, epd, eps and epc might be different in liblocation version 0.99-1 and older.

An application receiving a fix cannot know if the fix is a result from location method it requested. Therefore application should study whether fix is accurate enough to satisfy application's needs. This can be done by inspecting "eph" field, which is fix's horizontal accuracy in centimeters. Typical values for horizontal accuracies can be seen in the location methods table. If accuracy is not known, it has a value of <code>NaN.

The most useful signal in liblocation is LocationGPSDevice's changed signal, which is emitted everytime a new fix is received. LocationGPSDControl has an error-verbose signal which is emitted in case of an error. There is also a legacy signal error, which doesn't give a reason for error.

Liblocation sends a changed signal also after locationing is started or stopped, in which case a last known fix is sent if such exists. Application can differentiate these fixes from real ones by inspecting device->status field which equals LOCATION_GPS_DEVICE_STATUS_NO_FIX if the fix is not real.

Finally after everything above has been done, locationing can be started.

location_gpsd_control_start(control);

If the chosen location method violates control panel location settings, then a dialog is shown to user. Dialogs ask user to enable necessary services. On user's refusal an error to application is sent. If no error is seen, fixes should be coming after a while. When locationing is no longer needed, it can be stopped.