Location¶
See the Location guide.
Device location: one fix, or a stream of them.
Enable it in pythonnative.toml:
Example
Classes:
| Name | Description |
|---|---|
Position |
One location fix. |
Location |
Location services. |
Attributes:
| Name | Type | Description |
|---|---|---|
Accuracy |
Balanced accuracy saves power; high asks for the best the device can do. |
Accuracy
module-attribute
¶
Accuracy = Literal['balanced', 'high']
Balanced accuracy saves power; high asks for the best the device can do.
Position
dataclass
¶
Position(
latitude: float,
longitude: float,
accuracy: Optional[float] = None,
altitude: Optional[float] = None,
speed: Optional[float] = None,
heading: Optional[float] = None,
timestamp: Optional[float] = None,
)
One location fix.
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
Degrees north. |
longitude |
float
|
Degrees east. |
accuracy |
Optional[float]
|
Horizontal accuracy in meters, when reported. |
altitude |
Optional[float]
|
Meters above sea level, when reported. |
speed |
Optional[float]
|
Meters per second, when reported. |
heading |
Optional[float]
|
Degrees clockwise from north, when reported. |
timestamp |
Optional[float]
|
Unix seconds, when reported. |
Location
¶
Location services.
Raises:
| Type | Description |
|---|---|
NativeModuleError
|
If the native module fails, or with the code
|
Methods:
| Name | Description |
|---|---|
get_current |
Request the device's current location, prompting for permission if needed. |
watch |
Yield positions as the device moves, until the iteration ends. |
get_current
async
staticmethod
¶
Request the device's current location, prompting for permission if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
Accuracy
|
How hard to try for a precise fix. |
'balanced'
|
timeout
|
float
|
Maximum seconds to wait. |
10.0
|
Returns:
| Type | Description |
|---|---|
Optional[Position]
|
The position, or |
Optional[Position]
|
services are off, or the request timed out. |
watch
async
staticmethod
¶
watch(
*,
accuracy: Accuracy = "balanced",
distance: float = 0.0
) -> AsyncGenerator[Position, None]
Yield positions as the device moves, until the iteration ends.
Prompts for permission when needed. Leaving the async for (or
canceling its task) stops the updates, so this is safe to run from
use_effect. The iterator ends only when the caller stops it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accuracy
|
Accuracy
|
How hard to try for a precise fix. |
'balanced'
|
distance
|
float
|
Meters the device must move between updates. |
0.0
|
Raises:
| Type | Description |
|---|---|
NativeModuleError
|
With the code |