juno.location¶
Location services and geocoding via CoreLocation.
Wraps CLLocationManager for one-shot and continuous location
queries, plus CLGeocoder for forward and reverse geocoding.
Authorization is requested lazily by get_current() and updates()
when needed. The first call from a fresh install presents the system
prompt; subsequent calls reuse the granted (or denied) status. On
denial / restriction these helpers raise PermissionError so user
scripts can fall back gracefully.
Typical usage:
from juno import location
here = location.get_current()
print(here.latitude, here.longitude)
with location.updates():
for _ in range(10):
sample = location.get_latest()
if sample is not None:
print(sample.latitude, sample.longitude)
time.sleep(1)
matches = location.geocode("1 Infinite Loop, Cupertino")
place = location.reverse_geocode(37.3318, -122.0312)[0]
print(place.country, place.locality)
- class juno.location.Location(latitude, longitude, altitude, horizontal_accuracy, vertical_accuracy, speed, course, timestamp)¶
Bases:
objectA point-in-time location reading.
Negative
horizontal_accuracy/vertical_accuracyindicate that the dimension is unavailable.timestampis seconds since the Unix epoch.
- class juno.location.Placemark(latitude, longitude, name, country, country_code, administrative_area, sub_administrative_area, locality, sub_locality, thoroughfare, sub_thoroughfare, postal_code, timezone)¶
Bases:
objectA geocoded address record returned by
geocode()/reverse_geocode(). All string fields may beNonewhen the underlying CLPlacemark did not provide them.- Parameters:
latitude (float | None)
longitude (float | None)
name (str | None)
country (str | None)
country_code (str | None)
administrative_area (str | None)
sub_administrative_area (str | None)
locality (str | None)
sub_locality (str | None)
thoroughfare (str | None)
sub_thoroughfare (str | None)
postal_code (str | None)
timezone (str | None)
- class juno.location.AuthorizationStatus¶
Bases:
objectString constants returned by
authorization_status().
- juno.location.authorization_status()¶
Return the current location authorization status.
- Returns:
One of the
AuthorizationStatusstring constants.- Return type:
- juno.location.is_authorized()¶
Return
Trueif the app has any location authorization.- Return type:
- juno.location.request_authorization()¶
Request “when in use” authorization if status is undetermined.
If the status is already determined, returns immediately with the existing value. Otherwise this triggers the system permission prompt and polls
authorization_status()until the user makes a choice — that polling is in Python so Juno’s Stop button can interrupt the wait via a normalKeyboardInterrupt.- Returns:
Resolved authorization status, one of the
AuthorizationStatusconstants.- Return type:
- juno.location.get_current(timeout=30.0)¶
Request a single fresh location.
- Parameters:
timeout (float) – Maximum wait in seconds before raising
TimeoutError. Must be positive.- Returns:
A
Locationsnapshot.- Raises:
TypeError – If
timeoutis not a real number.ValueError – If
timeoutis not positive.PermissionError – If location authorization is denied or restricted.
TimeoutError – If no location was produced before
timeout.
- Return type:
- juno.location.updates()¶
Context manager that starts and stops continuous location updates.
Inside the
withblockget_latest()returns the most recently delivered location. When the block exits, updates are stopped and the cached value is cleared.- Raises:
PermissionError – If location authorization is denied or restricted when the block is entered.
- Return type:
Iterator[None]
- juno.location.is_updating()¶
Return whether a continuous-updates session is currently active.
Mirrors whether the most recent
updates()context manager is still running. Independent of whether a reading has been received yet — useget_latest()to check for that.- Return type:
- juno.location.get_latest()¶
Return the latest continuous-update location, or
Noneif none has been received yet.- Return type:
Location | None
- juno.location.geocode(address)¶
Forward geocode an address string to one or more placemarks.
- Parameters:
address (str) – Free-form address (e.g.
"1 Infinite Loop, Cupertino").- Returns:
A list of
Placemarkmatches, possibly empty.- Raises:
TypeError – If
addressis not a string.RuntimeError – If the geocoder failed (network unavailable, rate-limited, or unsupported address).
- Return type:
- juno.location.reverse_geocode(latitude, longitude)¶
Reverse geocode a coordinate pair to one or more placemarks.