Editing PyMaemo/Using Location API
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 11: | Line 11: | ||
import location | import location | ||
</source> | </source> | ||
- | Liblocation has two public <code>GObject</code>s. <code>GPSDControl</code | + | Liblocation has two public <code>GObject</code>s. <code>GPSDControl</code. is used for starting and stopping of location services, setting location method and interval, and listening for errors. <code>GPSDevice</code> has information about device status and contains the actual fix when one exists. The two <code>GObjects</code> are initiated as follows. |
<source lang="python"> | <source lang="python"> | ||
control = location.GPSDControl.get_default() | control = location.GPSDControl.get_default() | ||
device = location.GPSDevice() | device = location.GPSDevice() | ||
</source> | </source> | ||
- | |||
== Location methods == | == Location methods == | ||
Line 25: | Line 24: | ||
* <code>location.METHOD_ACWP</code> (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. | * <code>location.METHOD_ACWP</code> (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. | ||
* <code>location.METHOD_GNSS</code> (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. | * <code>location.METHOD_GNSS</code> (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. | ||
- | * <code>location.METHOD_AGNSS</code | + | * <code>location.METHOD_AGNSS</code (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 <code>GPSDevice</code>'s " | + | 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 <code>GPSDevice</code>'s "changed" signal, therefore application should judge whether fix it is receiving, is one that it needs. See [[#GPSDevice and GPSDeviceFix|GPSDeviceFix]] 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. | 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. | ||
Line 45: | Line 44: | ||
Here is table that summarizes differences between the methods. Accuracy refers to horizontal accuracy of the fix. | Here is table that summarizes differences between the methods. Accuracy refers to horizontal accuracy of the fix. | ||
- | {| class="wikitable" | + | {| class="wikitable" style="margin: 1em auto 1em auto" |
- | + | ||
- | + | ||
! Method !! Typical accuracy !! Requires SIM !! Requires network !! Drains battery | ! Method !! Typical accuracy !! Requires SIM !! Requires network !! Drains battery | ||
|- | |- | ||
- | | CWP || | + | | CWP || 1km-1000km || Yes || No || No |
|- | |- | ||
- | | ACWP || | + | | ACWP || 1km-10km || Yes || Yes || No |
|- | |- | ||
- | | GNSS || | + | | GNSS || 5m-100m || No || No || Yes |
|- | |- | ||
- | | AGNSS || | + | | AGNSS || 5m-100m || Yes || Yes || Yes |
|} | |} | ||
Line 69: | Line 66: | ||
== GPSDevice and GPSDeviceFix == | == GPSDevice and GPSDeviceFix == | ||
- | <code>GPSDevice</code> object has the following attributes ('''FIXME:''' currently " | + | <code>GPSDevice</code> object has the following attributes ('''FIXME:''' currently "satellites" and "cell_info" attributes are not supported in Python): |
- | * | + | *online: Whether there is a connection to the hardware |
- | * | + | *status: Status of the device |
- | * | + | *fix: Tuple containing actual fix data (latitude, longitude, etc) |
- | * | + | *satellites_in_view: Number of satellites in view |
- | * | + | *satellites_in_use: Number of satellites in use |
- | * | + | *satellites: Tuple containing information about satellites |
- | * | + | *cell_info: Tuple containing information about cell the device is connected to |
- | The most useful attribute is naturally the " | + | The most useful attribute is naturally the "fix" tuple which contains position and movement of the device and accuracies for them. The available information is listed below (in the order they appear on the tuple). In parenthesis there is a identifier which can be bitwisely anded with the "fields" value, to see whether corresponding tuple value is set. |
- | * | + | *mode: The mode of the fix |
- | * | + | *fields: A bitfield representing which items of this tuple contain valid data |
- | * | + | *time: The timestamp of the update (<code>location.GPS_DEVICE_TIME_SET</code>) |
- | * | + | *ept: Time accuracy |
- | * | + | *latitude: Fix latitude (<code>location.GPS_DEVICE_LATLONG_SET</code>) |
- | * | + | *longitude: Fix longitude (<code>location.GPS_DEVICE_LATLONG_SET</code>) |
- | * | + | *eph: Horizontal position accuracy |
- | * | + | *altitude: Fix altitude in meters (<code>location.GPS_DEVICE_ALTITUDE_SET</code>) |
- | *double | + | *double epv: Vertical position accuracy |
- | * | + | *track: Direction of motion in degrees (<code>location.GPS_DEVICE_TRACK_SET</code>) |
- | * | + | *epd: Track accuracy |
- | * | + | *speed: Current speed in km/h (<code>location.GPS_DEVICE_SPEED_SET</code>) |
- | * | + | *eps: Speed accuracy |
- | * | + | *climb: Current rate of climb in m/s (<code>location.GPS_DEVICE_CLIMB_SET</code>) |
- | * | + | *epc: Climb accuracy |
- | 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 " | + | 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 NaN. |
== Liblocation signals and callbacks == | == Liblocation signals and callbacks == | ||
Line 139: | Line 136: | ||
print "Satellites in view: %d, in use: %d" % (device.satellites_in_view, device.satellites_in_use) | print "Satellites in view: %d, in use: %d" % (device.satellites_in_view, device.satellites_in_use) | ||
</source> | </source> | ||
- | Liblocation sends a " | + | 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 <code>device.status</code> attribute which equals <code>location.GPS_DEVICE_STATUS_NO_FIX</code> if the fix is not real. |
== Starting and stopping locationing == | == Starting and stopping locationing == | ||
Line 168: | Line 165: | ||
if device.fix[1] & location.GPS_DEVICE_LATLONG_SET: | if device.fix[1] & location.GPS_DEVICE_LATLONG_SET: | ||
print "lat = %f, long = %f" % device.fix[4:6] | print "lat = %f, long = %f" % device.fix[4:6] | ||
- | + | data.stop() | |
def on_stop(control, data): | def on_stop(control, data): |
Learn more about Contributing to the wiki.