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>. 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.
+
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> (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.
+
* <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 "<code>changed</code>" signal, therefore application should judge whether fix it is receiving, is one that it needs. See [[#GPSDevice and GPSDeviceFix|GPSDeviceFix]] section for discussion.
+
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"
-
|+ Available location methods
+
-
|-
+
! Method !! Typical accuracy !! Requires SIM !! Requires network !! Drains battery
! Method !! Typical accuracy !! Requires SIM !! Requires network !! Drains battery
|-
|-
-
| CWP || 1 - 1000 km || Yes || No || No
+
| CWP || 1km-1000km || Yes || No || No
|-
|-
-
| ACWP || 1 - 10 km || Yes || Yes || No
+
| ACWP || 1km-10km || Yes || Yes || No
|-
|-
-
| GNSS || 5 - 100 m || No || No || Yes
+
| GNSS || 5m-100m || No || No || Yes
|-
|-
-
| AGNSS || 5 - 100 m || Yes || Yes || Yes
+
| 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>satellites</code>" and "<code>cell_info</code>" attributes are not supported in Python):
+
<code>GPSDevice</code> object has the following attributes ('''FIXME:''' currently "satellites" and "cell_info" attributes are not supported in Python):
-
*<code>online</code>: Whether there is a connection to the hardware
+
*online: Whether there is a connection to the hardware
-
*<code>status</code>: Status of the device
+
*status: Status of the device
-
*<code>fix</code>: Tuple containing actual fix data (latitude, longitude, etc)
+
*fix: Tuple containing actual fix data (latitude, longitude, etc)
-
*<code>satellites_in_view</code>: Number of satellites in view
+
*satellites_in_view: Number of satellites in view
-
*<code>satellites_in_use</code>: Number of satellites in use
+
*satellites_in_use: Number of satellites in use
-
*<code>satellites</code>: Tuple containing information about satellites
+
*satellites: Tuple containing information about satellites
-
*<code>cell_info</code>: Tuple containing information about cell the device is connected to
+
*cell_info: Tuple containing information about cell the device is connected to
-
The most useful attribute is naturally the "<code>fix</code>" 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.
+
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.
-
*<code>mode</code>: The mode of the fix
+
*mode: The mode of the fix
-
*<code>fields</code>: A bitfield representing which items of this tuple contain valid data
+
*fields: A bitfield representing which items of this tuple contain valid data
-
*<code>time</code>: The timestamp of the update (<code>location.GPS_DEVICE_TIME_SET</code>)
+
*time: The timestamp of the update (<code>location.GPS_DEVICE_TIME_SET</code>)
-
*<code>ept</code>: Time accuracy
+
*ept: Time accuracy
-
*<code>latitude</code>: Fix latitude (<code>location.GPS_DEVICE_LATLONG_SET</code>)
+
*latitude: Fix latitude (<code>location.GPS_DEVICE_LATLONG_SET</code>)
-
*<code>longitude</code>: Fix longitude (<code>location.GPS_DEVICE_LATLONG_SET</code>)
+
*longitude: Fix longitude (<code>location.GPS_DEVICE_LATLONG_SET</code>)
-
*<code>eph</code>: Horizontal position accuracy
+
*eph: Horizontal position accuracy
-
*<code>altitude</code>: Fix altitude in meters (<code>location.GPS_DEVICE_ALTITUDE_SET</code>)
+
*altitude: Fix altitude in meters (<code>location.GPS_DEVICE_ALTITUDE_SET</code>)
-
*double <code>epv</code>: Vertical position accuracy
+
*double epv: Vertical position accuracy
-
*<code>track</code>: Direction of motion in degrees (<code>location.GPS_DEVICE_TRACK_SET</code>)
+
*track: Direction of motion in degrees (<code>location.GPS_DEVICE_TRACK_SET</code>)
-
*<code>epd</code>: Track accuracy
+
*epd: Track accuracy
-
*<code>speed</code>: Current speed in km/h (<code>location.GPS_DEVICE_SPEED_SET</code>)
+
*speed: Current speed in km/h (<code>location.GPS_DEVICE_SPEED_SET</code>)
-
*<code>eps</code>: Speed accuracy
+
*eps: Speed accuracy
-
*<code>climb</code>: Current rate of climb in m/s (<code>location.GPS_DEVICE_CLIMB_SET</code>)
+
*climb: Current rate of climb in m/s (<code>location.GPS_DEVICE_CLIMB_SET</code>)
-
*<code>epc</code>: Climb accuracy
+
*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 "<code>eph</code>" 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.
+
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 "<code>changed</code>" 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.
+
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() commented out to allow continuous loop for a reliable fix - press ctrl c to break the loop, or program your own way of exiting)
+
             data.stop()
def on_stop(control, data):
def on_stop(control, data):

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)