objc2_core_location/
location.rs

1//! Inlined from the underscore-named framework _LocationEssentials, was moved
2//! from CoreLocation to there in Xcode 26, but it probably intended to be a
3//! private implementation detail.
4//!
5//! Find it with:
6//! ```sh
7//! ls $(xcrun --show-sdk-path)/System/Library/Frameworks/_LocationEssentials.framework/Headers/CLLocationEssentials.h
8//! ```
9#![allow(non_snake_case, unused_imports)]
10#![allow(clippy::missing_safety_doc)]
11#![allow(clippy::too_many_arguments)]
12use core::ffi::c_double;
13use core::ptr::NonNull;
14use objc2::encode::{Encode, Encoding, RefEncode};
15use objc2::rc::{Allocated, Retained};
16use objc2::runtime::Bool;
17use objc2::{extern_class, extern_conformance, extern_methods};
18use objc2_foundation::{
19    CopyingHelper, NSCoding, NSCopying, NSDate, NSInteger, NSObject, NSObjectProtocol,
20    NSSecureCoding, NSTimeInterval,
21};
22
23/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdegrees?language=objc)
24pub type CLLocationDegrees = c_double;
25
26/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationaccuracy?language=objc)
27pub type CLLocationAccuracy = c_double;
28
29/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationspeed?language=objc)
30pub type CLLocationSpeed = c_double;
31
32/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationspeedaccuracy?language=objc)
33pub type CLLocationSpeedAccuracy = c_double;
34
35/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdirection?language=objc)
36pub type CLLocationDirection = c_double;
37
38/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdirectionaccuracy?language=objc)
39pub type CLLocationDirectionAccuracy = c_double;
40
41/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationcoordinate2d?language=objc)
42#[repr(C)]
43#[derive(Clone, Copy, Debug, PartialEq)]
44pub struct CLLocationCoordinate2D {
45    pub latitude: CLLocationDegrees,
46    pub longitude: CLLocationDegrees,
47}
48
49unsafe impl Encode for CLLocationCoordinate2D {
50    const ENCODING: Encoding = Encoding::Struct(
51        "CLLocationCoordinate2D",
52        &[<CLLocationDegrees>::ENCODING, <CLLocationDegrees>::ENCODING],
53    );
54}
55
56unsafe impl RefEncode for CLLocationCoordinate2D {
57    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
58}
59
60/// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdistance?language=objc)
61pub type CLLocationDistance = c_double;
62
63extern "C" {
64    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcldistancefilternone?language=objc)
65    pub static kCLDistanceFilterNone: CLLocationDistance;
66}
67
68extern "C" {
69    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracybestfornavigation?language=objc)
70    pub static kCLLocationAccuracyBestForNavigation: CLLocationAccuracy;
71}
72
73extern "C" {
74    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracybest?language=objc)
75    pub static kCLLocationAccuracyBest: CLLocationAccuracy;
76}
77
78extern "C" {
79    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracynearesttenmeters?language=objc)
80    pub static kCLLocationAccuracyNearestTenMeters: CLLocationAccuracy;
81}
82
83extern "C" {
84    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracyhundredmeters?language=objc)
85    pub static kCLLocationAccuracyHundredMeters: CLLocationAccuracy;
86}
87
88extern "C" {
89    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracykilometer?language=objc)
90    pub static kCLLocationAccuracyKilometer: CLLocationAccuracy;
91}
92
93extern "C" {
94    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracythreekilometers?language=objc)
95    pub static kCLLocationAccuracyThreeKilometers: CLLocationAccuracy;
96}
97
98extern "C" {
99    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationaccuracyreduced?language=objc)
100    pub static kCLLocationAccuracyReduced: CLLocationAccuracy;
101}
102
103extern "C" {
104    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationdistancemax?language=objc)
105    pub static CLLocationDistanceMax: CLLocationDistance;
106}
107
108extern "C" {
109    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cltimeintervalmax?language=objc)
110    pub static CLTimeIntervalMax: NSTimeInterval;
111}
112
113extern "C" {
114    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/kcllocationcoordinate2dinvalid?language=objc)
115    pub static kCLLocationCoordinate2DInvalid: CLLocationCoordinate2D;
116}
117
118impl CLLocationCoordinate2D {
119    #[doc(alias = "CLLocationCoordinate2DIsValid")]
120    #[inline]
121    pub unsafe fn is_valid(self) -> bool {
122        extern "C-unwind" {
123            fn CLLocationCoordinate2DIsValid(coord: CLLocationCoordinate2D) -> Bool;
124        }
125        unsafe { CLLocationCoordinate2DIsValid(self) }.as_bool()
126    }
127
128    #[doc(alias = "CLLocationCoordinate2DMake")]
129    #[inline]
130    pub unsafe fn new(
131        latitude: CLLocationDegrees,
132        longitude: CLLocationDegrees,
133    ) -> CLLocationCoordinate2D {
134        extern "C-unwind" {
135            fn CLLocationCoordinate2DMake(
136                latitude: CLLocationDegrees,
137                longitude: CLLocationDegrees,
138            ) -> CLLocationCoordinate2D;
139        }
140        unsafe { CLLocationCoordinate2DMake(latitude, longitude) }
141    }
142}
143
144extern_class!(
145    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/clfloor?language=objc)
146    #[unsafe(super(NSObject))]
147    #[derive(Debug, PartialEq, Eq, Hash)]
148    pub struct CLFloor;
149);
150
151extern_conformance!(
152    unsafe impl NSCoding for CLFloor {}
153);
154
155extern_conformance!(
156    unsafe impl NSCopying for CLFloor {}
157);
158
159unsafe impl CopyingHelper for CLFloor {
160    type Result = Self;
161}
162
163extern_conformance!(
164    unsafe impl NSObjectProtocol for CLFloor {}
165);
166
167extern_conformance!(
168    unsafe impl NSSecureCoding for CLFloor {}
169);
170
171impl CLFloor {
172    extern_methods!(
173        #[unsafe(method(level))]
174        #[unsafe(method_family = none)]
175        pub unsafe fn level(&self) -> NSInteger;
176    );
177}
178
179/// Methods declared on superclass `NSObject`.
180impl CLFloor {
181    extern_methods!(
182        #[unsafe(method(init))]
183        #[unsafe(method_family = init)]
184        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
185
186        #[unsafe(method(new))]
187        #[unsafe(method_family = new)]
188        pub unsafe fn new() -> Retained<Self>;
189    );
190}
191
192extern_class!(
193    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocationsourceinformation?language=objc)
194    #[unsafe(super(NSObject))]
195    #[derive(Debug, PartialEq, Eq, Hash)]
196    pub struct CLLocationSourceInformation;
197);
198
199extern_conformance!(
200    unsafe impl NSCoding for CLLocationSourceInformation {}
201);
202
203extern_conformance!(
204    unsafe impl NSCopying for CLLocationSourceInformation {}
205);
206
207unsafe impl CopyingHelper for CLLocationSourceInformation {
208    type Result = Self;
209}
210
211extern_conformance!(
212    unsafe impl NSObjectProtocol for CLLocationSourceInformation {}
213);
214
215extern_conformance!(
216    unsafe impl NSSecureCoding for CLLocationSourceInformation {}
217);
218
219impl CLLocationSourceInformation {
220    extern_methods!(
221        #[unsafe(method(initWithSoftwareSimulationState:andExternalAccessoryState:))]
222        #[unsafe(method_family = init)]
223        pub unsafe fn initWithSoftwareSimulationState_andExternalAccessoryState(
224            this: Allocated<Self>,
225            is_software: bool,
226            is_accessory: bool,
227        ) -> Retained<Self>;
228
229        #[unsafe(method(isSimulatedBySoftware))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn isSimulatedBySoftware(&self) -> bool;
232
233        #[unsafe(method(isProducedByAccessory))]
234        #[unsafe(method_family = none)]
235        pub unsafe fn isProducedByAccessory(&self) -> bool;
236    );
237}
238
239/// Methods declared on superclass `NSObject`.
240impl CLLocationSourceInformation {
241    extern_methods!(
242        #[unsafe(method(init))]
243        #[unsafe(method_family = init)]
244        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
245
246        #[unsafe(method(new))]
247        #[unsafe(method_family = new)]
248        pub unsafe fn new() -> Retained<Self>;
249    );
250}
251
252extern_class!(
253    /// [Apple's documentation](https://developer.apple.com/documentation/corelocation/cllocation?language=objc)
254    #[unsafe(super(NSObject))]
255    #[derive(Debug, PartialEq, Eq, Hash)]
256    pub struct CLLocation;
257);
258
259unsafe impl Send for CLLocation {}
260
261unsafe impl Sync for CLLocation {}
262
263extern_conformance!(
264    unsafe impl NSCoding for CLLocation {}
265);
266
267extern_conformance!(
268    unsafe impl NSCopying for CLLocation {}
269);
270
271unsafe impl CopyingHelper for CLLocation {
272    type Result = Self;
273}
274
275extern_conformance!(
276    unsafe impl NSObjectProtocol for CLLocation {}
277);
278
279extern_conformance!(
280    unsafe impl NSSecureCoding for CLLocation {}
281);
282
283impl CLLocation {
284    extern_methods!(
285        #[unsafe(method(initWithLatitude:longitude:))]
286        #[unsafe(method_family = init)]
287        pub unsafe fn initWithLatitude_longitude(
288            this: Allocated<Self>,
289            latitude: CLLocationDegrees,
290            longitude: CLLocationDegrees,
291        ) -> Retained<Self>;
292
293        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:timestamp:))]
294        #[unsafe(method_family = init)]
295        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_timestamp(
296            this: Allocated<Self>,
297            coordinate: CLLocationCoordinate2D,
298            altitude: CLLocationDistance,
299            h_accuracy: CLLocationAccuracy,
300            v_accuracy: CLLocationAccuracy,
301            timestamp: &NSDate,
302        ) -> Retained<Self>;
303
304        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:speed:timestamp:))]
305        #[unsafe(method_family = init)]
306        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_course_speed_timestamp(
307            this: Allocated<Self>,
308            coordinate: CLLocationCoordinate2D,
309            altitude: CLLocationDistance,
310            h_accuracy: CLLocationAccuracy,
311            v_accuracy: CLLocationAccuracy,
312            course: CLLocationDirection,
313            speed: CLLocationSpeed,
314            timestamp: &NSDate,
315        ) -> Retained<Self>;
316
317        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:courseAccuracy:speed:speedAccuracy:timestamp:))]
318        #[unsafe(method_family = init)]
319        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_course_courseAccuracy_speed_speedAccuracy_timestamp(
320            this: Allocated<Self>,
321            coordinate: CLLocationCoordinate2D,
322            altitude: CLLocationDistance,
323            h_accuracy: CLLocationAccuracy,
324            v_accuracy: CLLocationAccuracy,
325            course: CLLocationDirection,
326            course_accuracy: CLLocationDirectionAccuracy,
327            speed: CLLocationSpeed,
328            speed_accuracy: CLLocationSpeedAccuracy,
329            timestamp: &NSDate,
330        ) -> Retained<Self>;
331
332        #[unsafe(method(initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:courseAccuracy:speed:speedAccuracy:timestamp:sourceInfo:))]
333        #[unsafe(method_family = init)]
334        pub unsafe fn initWithCoordinate_altitude_horizontalAccuracy_verticalAccuracy_course_courseAccuracy_speed_speedAccuracy_timestamp_sourceInfo(
335            this: Allocated<Self>,
336            coordinate: CLLocationCoordinate2D,
337            altitude: CLLocationDistance,
338            h_accuracy: CLLocationAccuracy,
339            v_accuracy: CLLocationAccuracy,
340            course: CLLocationDirection,
341            course_accuracy: CLLocationDirectionAccuracy,
342            speed: CLLocationSpeed,
343            speed_accuracy: CLLocationSpeedAccuracy,
344            timestamp: &NSDate,
345            source_info: &CLLocationSourceInformation,
346        ) -> Retained<Self>;
347
348        /// This property is not atomic.
349        ///
350        /// # Safety
351        ///
352        /// This might not be thread-safe.
353        #[unsafe(method(coordinate))]
354        #[unsafe(method_family = none)]
355        pub unsafe fn coordinate(&self) -> CLLocationCoordinate2D;
356
357        /// This property is not atomic.
358        ///
359        /// # Safety
360        ///
361        /// This might not be thread-safe.
362        #[unsafe(method(altitude))]
363        #[unsafe(method_family = none)]
364        pub unsafe fn altitude(&self) -> CLLocationDistance;
365
366        /// This property is not atomic.
367        ///
368        /// # Safety
369        ///
370        /// This might not be thread-safe.
371        #[unsafe(method(ellipsoidalAltitude))]
372        #[unsafe(method_family = none)]
373        pub unsafe fn ellipsoidalAltitude(&self) -> CLLocationDistance;
374
375        /// This property is not atomic.
376        ///
377        /// # Safety
378        ///
379        /// This might not be thread-safe.
380        #[unsafe(method(horizontalAccuracy))]
381        #[unsafe(method_family = none)]
382        pub unsafe fn horizontalAccuracy(&self) -> CLLocationAccuracy;
383
384        /// This property is not atomic.
385        ///
386        /// # Safety
387        ///
388        /// This might not be thread-safe.
389        #[unsafe(method(verticalAccuracy))]
390        #[unsafe(method_family = none)]
391        pub unsafe fn verticalAccuracy(&self) -> CLLocationAccuracy;
392
393        /// This property is not atomic.
394        ///
395        /// # Safety
396        ///
397        /// This might not be thread-safe.
398        #[unsafe(method(course))]
399        #[unsafe(method_family = none)]
400        pub unsafe fn course(&self) -> CLLocationDirection;
401
402        /// This property is not atomic.
403        ///
404        /// # Safety
405        ///
406        /// This might not be thread-safe.
407        #[unsafe(method(courseAccuracy))]
408        #[unsafe(method_family = none)]
409        pub unsafe fn courseAccuracy(&self) -> CLLocationDirectionAccuracy;
410
411        /// This property is not atomic.
412        ///
413        /// # Safety
414        ///
415        /// This might not be thread-safe.
416        #[unsafe(method(speed))]
417        #[unsafe(method_family = none)]
418        pub unsafe fn speed(&self) -> CLLocationSpeed;
419
420        /// This property is not atomic.
421        ///
422        /// # Safety
423        ///
424        /// This might not be thread-safe.
425        #[unsafe(method(speedAccuracy))]
426        #[unsafe(method_family = none)]
427        pub unsafe fn speedAccuracy(&self) -> CLLocationSpeedAccuracy;
428
429        /// This property is not atomic.
430        ///
431        /// # Safety
432        ///
433        /// This might not be thread-safe.
434        #[unsafe(method(timestamp))]
435        #[unsafe(method_family = none)]
436        pub unsafe fn timestamp(&self) -> Retained<NSDate>;
437
438        /// This property is not atomic.
439        ///
440        /// # Safety
441        ///
442        /// This might not be thread-safe.
443        #[unsafe(method(floor))]
444        #[unsafe(method_family = none)]
445        pub unsafe fn floor(&self) -> Option<Retained<CLFloor>>;
446
447        /// This property is not atomic.
448        ///
449        /// # Safety
450        ///
451        /// This might not be thread-safe.
452        #[unsafe(method(sourceInformation))]
453        #[unsafe(method_family = none)]
454        pub unsafe fn sourceInformation(&self) -> Option<Retained<CLLocationSourceInformation>>;
455
456        #[deprecated]
457        #[unsafe(method(getDistanceFrom:))]
458        #[unsafe(method_family = none)]
459        pub unsafe fn getDistanceFrom(&self, location: &CLLocation) -> CLLocationDistance;
460
461        #[unsafe(method(distanceFromLocation:))]
462        #[unsafe(method_family = none)]
463        pub unsafe fn distanceFromLocation(&self, location: &CLLocation) -> CLLocationDistance;
464    );
465}
466
467/// Methods declared on superclass `NSObject`.
468impl CLLocation {
469    extern_methods!(
470        #[unsafe(method(init))]
471        #[unsafe(method_family = init)]
472        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
473
474        #[unsafe(method(new))]
475        #[unsafe(method_family = new)]
476        pub unsafe fn new() -> Retained<Self>;
477    );
478}
479
480#[deprecated = "renamed to `CLLocationCoordinate2D::is_valid`"]
481#[inline]
482pub unsafe extern "C-unwind" fn CLLocationCoordinate2DIsValid(
483    coord: CLLocationCoordinate2D,
484) -> bool {
485    extern "C-unwind" {
486        fn CLLocationCoordinate2DIsValid(coord: CLLocationCoordinate2D) -> Bool;
487    }
488    unsafe { CLLocationCoordinate2DIsValid(coord) }.as_bool()
489}
490
491extern "C-unwind" {
492    #[deprecated = "renamed to `CLLocationCoordinate2D::new`"]
493    pub fn CLLocationCoordinate2DMake(
494        latitude: CLLocationDegrees,
495        longitude: CLLocationDegrees,
496    ) -> CLLocationCoordinate2D;
497}