Debian Codegraph @

plyer/facades/gps.py

raw symbols SCIP
1 '''
2 GPS
3 ====
4
5 .. versionadded:: 1.1
6
7 .. note::
8 On Android `INTERNET`, `ACCESS_FINE_LOCATION`, `ACCESS_COARSE_LOCATION`
9 permissions are needed.
10
11
12 .. note::
13 On iOS `NSLocationWhenInUseUsageDescription` key is required for app to
14 display geolocation usage permission prompt. Key can be added in Xcode
15 target `info` section or in ``Resources/<YourApp>-info.plist``.
16 App background mode (`on_pause`) also must be supported.
17
18 You need to set a `on_location` callback with the :meth:`configure` method.
19 This callback will receive a couple of keywords / values, that might be
20 different depending of their availability on the targeted platform.
21 Lat and lon are always available.
22
23 - lat: latitude of the last location, in degrees
24 - lon: longitude of the last location, in degrees
25 - speed: speed of the user, in meters/second over ground
26 - bearing: bearing in degrees
27 - altitude: altitude in meters above the sea level
28
29 Here is an example of the usage of gps::
30
31 from plyer import gps
32
33 def print_locations(**kwargs):
34 print 'lat: {lat}, lon: {lon}'.format(**kwargs)
35
36 gps.configure(on_location=print_locations)
37 gps.start()
38 # later
39 gps.stop()
40
41 Supported Platforms
42 -------------------
43 Android, iOS
44
45 '''
46
47
48 class GPS:
49 '''
50 GPS facade.
51 '''
52
53 def configure(self, on_location, on_status=None):
54 '''
55 Configure the GPS object. This method should be called before
56 :meth:`start`.
57
58 :param on_location: Function to call when receiving a new location
59 :param on_status: Function to call when a status message is received
60 :type on_location: callable, multiples keys/value will be passed.
61 :type on_status: callable, args are "message-type", "status"
62
63 .. warning::
64
65 The `on_location` and `on_status` callables might be called from
66 another thread than the thread used for creating the GPS object.
67 '''
68 self.on_location = on_location
69 self.on_status = on_status
70 self._configure()
71
72 def start(self, minTime=1000, minDistance=1):
73 '''
74 Start the GPS location updates.
75 Expects 2 parameters:
76 minTime: milliseconds. (float)
77 minDistance: meters. (float)
78 '''
79 self._start(minTime=minTime, minDistance=minDistance)
80
81 def stop(self):
82 '''
83 Stop the GPS location updates.
84 '''
85 self._stop()
86
87 # private
88
89 def _configure(self):
90 raise NotImplementedError()
91
92 def _start(self, **kwargs):
93 raise NotImplementedError()
94
95 def _stop(self):
96 raise NotImplementedError()