Core Location

RSS for tag

Obtain the geographic location and orientation of a device using Core Location.

Core Location Documentation

Posts under Core Location tag

165 Posts
Sort by:
Post not yet marked as solved
0 Replies
183 Views
If they had used .task they could have removed the class LocationsHandler: ObservableObject and simply done: struct ContentView: View { @State var lastLocation: CLLocation? var body: some View { VStack { ... } .task { let updates = CLLocationUpdate.liveUpdates() for try await update in updates { if let loc = update.location { self.lastLocation = loc } } } And saved themselves about 20 or so lines of code. .task was added in the year before so it isn't the case that it wasn't available to the CoreLocation team yet. To wrap async/await in a Combine's ObservableObject is very strange. They could have also used @AppStorage instead of UserDefaults and saved another few lines. To be honest this is some of the strangest SwiftUI code I've seen.
Posted
by malc.
Last updated
.
Post not yet marked as solved
0 Replies
218 Views
Hey I try to post my issue here but keep getting a sensitive problem, so I posted on stack overflow (See here), but really appreciate your help on any forum. The post is about an issue with the auto refresh of the widget and the same behaviour when refreshing from a button in the widget (Done with AppIntent).
Posted
by aimarquez.
Last updated
.
Post not yet marked as solved
0 Replies
174 Views
Hi I want to inquire about the data returned from CoreLocation update and whether it is accurate. I am attempting to retrieve the local address in Japan based on the postal code, and I have observed differences in the returned data. When calling the information retrieval function with the postal code 3360042, the returned data is as follows: Locality: さいたま市 SubLocality: 南区 Corresponding to Japan Post: https://www.post.japanpost.jp/cgi-zip/zipcode.php?pref=11&city=1111080&id=38748 the displayed information on the website includes "Locality + SubLocality". When calling the information retrieval function with the postal code 1350064, the returned data is as follows: Locality: 江東区 SubLocality: 青海 Corresponding to Japan Post japan post: https://www.post.japanpost.jp/cgi-zip/zipcode.php?pref=11&city=1111080&id=38748 the displayed information on the website only includes "Locality" not includes SubLocality. Is it possible that CoreLocation has been updated? The current data seems to deviate from the design of our application. Please provide me with a solution to determine when to use "Locality + SubLocality" versus just "Locality" to obtain the local address. Thank.
Posted Last updated
.
Post not yet marked as solved
1 Replies
340 Views
In our app we have the necessity to gather background location after a trigger from a bluetooth event. During the onboarding we ask for authorizedWhenInUse. CLLocationManageris configured like this, and in capabilities we provided the location flag. let cl = CLLocationManager() cl.delegate = self cl.allowsBackgroundLocationUpdates = true cl.desiredAccuracy = kCLLocationAccuracyBestForNavigation According to apple doc or at least what I understood, this should be enough to obtain locations even when the app is in background (and awake). The system allows background updates for apps with either When in Use or Always authorization. If an app isn't running when an update occurs, the system launches the app only if it has Always authorization and uses the significant location change, visits, or region monitoring services. We saw an inconsistent bahviour, the system request to start the location updates after the bluetooth event (we have background capabilities set also for that). In foreground it work always, but in background sometimes it works and sometimes not. When we don't receive a location we usually get a CLError.denied in the func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) method. At this point I don't get the apple doc quote, is it possible to obtain location in background or not with authorizedWhenInUse?
Posted
by DrAma78.
Last updated
.
Post not yet marked as solved
1 Replies
243 Views
Hello, We have an iOS application which detects when the user starts driving by detecting an USB iBeacon which is installed in the car of the users. For that we are monitoring the iBeacon region with CoreLocation and we are detecting the iBeacon when the locationManager(_:didDetermineState:for:) delegate method is called. We received some reports from a user that the iBeacon monitoring stops working when a specific BT device (specifically a hearing aid) is connected to the iPhone. The hearing aid is connected in the iOS Settings > Bluetooth page, similar how a regular BT headset is connected. When the hearing aid is disconnected then the iBeacon monitoring resumes and starts working properly again. We can't reproduce this issue with our BT headsets, so maybe the problem is specific to just some BT device connections? The advertising time interval of the iBeacon is 100mS as requested in the Apple documentation. Previously we had problems when a phone call was made through a BT headset when we used an advertising interval > 100mS in order to improve the battery usage of the iBeacon. But we changed to use an USB iBeacon, so the battery usage is not a concern anymore. Did somebody experience similar issues or has a solution? Specifically, can some specific BT connections set up in iOS Settings > Bluetooth page interfere with the iBeacon monitoring when using CoreLocation? Thank you very much!
Posted Last updated
.
Post not yet marked as solved
0 Replies
270 Views
I managed to get the entry/exit for beacon region on >iOS 17.0 to <=iOS 17.1.2, but it doesn't work at all on latest iOS version 17.3.1. I have tried the new addition in iOS 17.2, assuming unmonitored as well but still no result. I'm using the sample code provided by apple, https://developer.apple.com/documentation/corelocation/monitoring_location_changes_with_core_location. Please guide.
Posted Last updated
.
Post not yet marked as solved
0 Replies
223 Views
although the Documentation implies that multiple CLLocationManager running in parallel should not intervene one another. I find some evidence that they do: for example a Medium posts title: "Single vs Multi CLLocationManager solutions" states: In multi instances of CLLocationManagers solution, there is the risk of collision where a feature / settings can impacts across instances of CLLocationManagers. another Medium post titled: "Measuring Differences of Degrees Using CLLocation’s CLHeading" states: however an important condition is that Apple recommends you initialize only ONE instance within your application at a time. This is because multiple instances running simultaneously has the effect of causing interference and distorting the data so is there some risk using CLLocationManager in parallel. is the configuration properties such as desiredAccuracy and distanceFilter can interrupt different CLLocationManagers running in parallel?
Posted Last updated
.
Post not yet marked as solved
0 Replies
244 Views
I'm trying to develop a iOS mobile app with using flutter, which can scan nearby wifi access points and connect to a one of them. I ran the app on a physical device with a free apple developer account. When I scan for the wifi access points, it throws an error with saying wifi scan is not supported. I just used wifi_scan library in flutter. Is it required to have a paid developer account to test this feature (wifi scanning and connection) ? Does iOS natively give the access to apps to scan wifi? Thanks
Posted
by Pabasara.
Last updated
.
Post not yet marked as solved
3 Replies
797 Views
I am working on an app where I need to orient a custom view depending on the device heading. I am using ARKit and ARSCNView with the ARGeoTrackingConfiguration in order to overlay my custom view in real world geographic coordinates. I've got a lot of it working, but the heading of my custom view is off. Once the ARSession gets a ARGeoTrackingStatus.State of .localized, I need to be able to get the devices heading (0-360) so that I can orient my view. I'm having trouble figuring out how to do this missing piece. Any help is appreciated.
Posted
by rolson.
Last updated
.
Post not yet marked as solved
0 Replies
250 Views
My macOS application is trying to fetch location, but everytime LocationManager responds with locationUnknown. Application is granted with permission to access location. Issue is seen in only one device with OSVersion: 14.2.1(23C71), chipset: Apple M1 pro. Other devices with same OS don't have this issue. My application is a background agent, means it has given UIElement in the plist. Issue persists even after restarting device, re-installing application, re-applying location permission. But Google Chrome shows correct location when using Openstreet Map or Google Maps. Is there any troubleshoot/alternative methods here? Any idea why it occurs? Code: if CLLocationManager.locationServicesEnabled() { if #available(OSX 10.14, *) { self.locationManager.requestLocation() } else { // Fallback on earlier versions self.locationManager.startUpdatingLocation() } } I need to get location in certain intervals. So After LocationManager updates I stop location with locationManager.stopUpdatingLocation() and request again after the interval.
Posted Last updated
.
Post not yet marked as solved
0 Replies
228 Views
Hi guys! I am trying to extract Location Services data from an iPhone running developer mode, and have installed the "Location Services for iOS" Profile that can be found on the Profiles and Logs page. I have also read the Instructions PDF, and done the setup. I am having a hard time finding the actual logs after exporting the sysdiagnose folder. The folder is quite big and complex. Can someone please help me, and tell me where I can find it? Thanks!
Posted
by rawpotao.
Last updated
.
Post not yet marked as solved
0 Replies
167 Views
The beacon device is very close to the phone(ios17). But the RSSI obtained from the beacon information returned by the locationManager's didRange function is always 0. Why? log: didRange [CLBeacon (uuid:D4C3CCC0-29FB-11E5-884F-0002A5D5C51B, major:0, minor:9, proximity:0 +/- -1.00m, rssi:0, timestamp:2024-02-15 06:48:57 +0000)] didRange [CLBeacon (uuid:D4C3CCC0-29FB-11E5-884F-0002A5D5C51B, major:0, minor:9, proximity:0 +/- -1.00m, rssi:0, timestamp:2024-02-15 06:48:58 +0000)] didRange [CLBeacon (uuid:D4C3CCC0-29FB-11E5-884F-0002A5D5C51B, major:0, minor:9, proximity:0 +/- -1.00m, rssi:0, timestamp:2024-02-15 06:48:59 +0000)] didRange [CLBeacon (uuid:D4C3CCC0-29FB-11E5-884F-0002A5D5C51B, major:0, minor:9, proximity:0 +/- -1.00m, rssi:0, timestamp:2024-02-15 06:49:00 +0000)]
Posted
by briskyoyo.
Last updated
.
Post not yet marked as solved
0 Replies
191 Views
Hi Developers. I need to try to embed GeoData into a USDZ model and then have the capabilities to "explore" the model while walking around in the real world. e.g. load and display a 3D model of Time Square and show a location pin which displays a users' virtual position on the model... when the user walks 10 meters north, in the real world, the location pin must move 10m (to scale) on the displayed model. As a new developer, I'm starting from scratch so would benefit greatly from having my hand held - please don't be afraid of patronizing me. Step 1 - load and display the 3D model Step 2 - geolocate the user Step 3 - translate the user's current position into a position on the 3D model and represent their "position" on the model with a traditional GPS location marker "pin". Step 4 - move the user's GPS pin on the mode, relative to (and reflecting) their actual real world movement. Is this acheivable or have I explained things to ambiguously? I look forward to hearing from my savior(s) as soon as convenient. Thank you in advance
Posted Last updated
.
Post not yet marked as solved
0 Replies
302 Views
CLMonitor WWDC video, it says the same name can be reused await CLMonitor("greeting") but the production iOS 17 API actually crashes. Is this the correct behaviour? (See screenshot 1) for try await events in monitor.events should work in from the WWDC video, but the production iOS 17 API does not work and need to insert await after in keyword. Also, never received any events from the monitor (See screenshot 2) WWDC Video: https://developer.apple.com/wwdc23/10147
Posted
by John-Doe.
Last updated
.
Post not yet marked as solved
1 Replies
352 Views
We are implementing indoor positioning and proximity sensing in our iOS app using iBeacons. We have placed multiple beacons to detect the proximity of one point of interest(POI). We are using the startRangingBeacons method in the CLLocationManager class and implementing corresponding delegates to receive the ranging information. With all required foreground and background permissions granted, when a user walks from one POI to another, beacon ranging is working as expected and we are continuously receiving the sightings in the app. We have observed that, if user stops walking for a few minutes at a POI and then device automatically pauses the scan. Hence, we will not receive any beacon signals. When there is a movement, it performs beacon ranging again for a minute or so, then stops again for longer time even when user is walking. The interval between the pausing and resuming the service is not a constant. We have also observed that sometimes it takes more than 15 minutes to resume the service once the system pauses the ranging automatically. Is it an expected behavior? How long does it usually take for beacon ranging services to resume after the user starts moving? Is there any way we can reduce this delay between the pause and resume of ranging beacons? Appreciate your support
Posted
by Mijesh.
Last updated
.
Post not yet marked as solved
0 Replies
248 Views
I'm trying to develop a watchOS app with location. I've got the proper privacy settings in the info.plist, similar code works on other devices. (also simulators). But on watchOS simulators everything is grayed out. Privacy & Location -> Location Services App shows up correctly, but everything is grayed out. I've tried: Different simulators (with/without paired iPhone) Different app configurations (Watch-Only app, Watch App with new companion) Toggling Supports Running Without iOS App Installation. It's always grayed out! This is with watchOS 10 simulators across any model, and Xcode 15.2 Any help would be appreciated.
Posted Last updated
.
Post not yet marked as solved
0 Replies
219 Views
I found something when I use CLLocationManagerDelegate on VisionOS. When I called func locationManagerDidChangeAuthorization func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) { switch manager.authorizationStatus { case .notDetermined, .denied: locationManager.requestWhenInUseAuthorization() default: locationManager.startUpdatingLocation() guard let center = locationManager.location?.coordinate else { return } isFollowing = false mapCamera = .region(.init(center: center, span: .init(latitudeDelta: 0.005, longitudeDelta: 0.005))) addItems() } } Although I choose allow auth, locationManagerDidChangeAuthorization wasn't called.
Posted Last updated
.
Post not yet marked as solved
0 Replies
275 Views
Hi All, I need user continues location event if app in background and terminated (Not-running) mode below is the code I'm using to get the location but still I'm not get the location continuously import BackgroundTasks import UIKit class AppDelegate: UIResponder, UIApplicationDelegate { var significatLocationManager: CLLocationManager? func startSignificationLocation() { self.significatLocationManager = CLLocationManager() self.significatLocationManager?.delegate = self self.significatLocationManager?.activityType = .fitness self.significatLocationManager?.distanceFilter = 10 self.significatLocationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters self.significatLocationManager?.allowsBackgroundLocationUpdates = true self.significatLocationManager?.pausesLocationUpdatesAutomatically = false self.significatLocationManager?.startUpdatingLocation() self.significatLocationManager?.startMonitoringSignificantLocationChanges() self.significatLocationManager?.requestAlwaysAuthorization() } func stopAllRegionMonitoring(locationManager:CLLocationManager?){ for delRegion in (locationManager?.monitoredRegions ?? []){locationManager?.stopMonitoring(for: delRegion)} } } extension AppDelegate: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { self.myLocation = locations.last //call update My Location API if (self.myLocation?.horizontalAccuracy ?? 0.0) <= (self.liveLocationTrackingRegionRadius + 15.0 ){ self.createRegion(location: self.myLocation) } else { manager.stopUpdatingLocation() manager.startUpdatingLocation() } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {} func locationManagerDidPauseLocationUpdates(_ manager: CLLocationManager) { manager.startUpdatingLocation() } func locationManagerDidResumeLocationUpdates(_ manager: CLLocationManager) { manager.startUpdatingLocation() } } extension AppDelegate { func createRegion(location:CLLocation?, type:LocationRegionMonitoringTyep = .LiveLocationTracking) { if self.significatLocationManager == nil { self.startSignificationLocation() } guard let location = location else { return } guard CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) else{ return } var identifier:String = "Live_Location_Tracking-" + "\(location.coordinate.latitude)" + "-" + "\(location.coordinate.longitude)" if (self.significatLocationManager?.monitoredRegions.count ?? 0) > 10 { self.stopAllRegionMonitoring(locationManager: self.significatLocationManager) } var region : CLCircularRegion? region = CLCircularRegion(center: CLLocationCoordinate2D(latitude: location.coordinate.latitude,longitude: location.coordinate.longitude),radius: 10.0 ,identifier: identifier) region?.notifyOnExit = true self.significatLocationManager?.startUpdatingLocation() if let reg = region { self.significatLocationManager?.startMonitoring(for: reg) } } func stopAllRegionMonitoring(locationManager:CLLocationManager?){ let WOMRequestId:String? = UserDefaultManager.shared.womEmergencyDetails?.data?.request?.id for delRegion in (locationManager?.monitoredRegions ?? []){ if let reqId = WOMRequestId { if delRegion.identifier.contains(reqId) { locationManager?.stopMonitoring(for: delRegion) } } else { locationManager?.stopMonitoring(for: delRegion) } } } func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) { if region.identifier.contains(AppConstants.WatchOverMe) { AppDelegate.shared?.isWOMReachDestination(location: manager.location, region: region) } } func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) { self.myLocation = manager.location manager.stopMonitoring(for: region) self.significatLocationManager?.stopMonitoring(for: region) manager.startUpdatingLocation() self.significatLocationManager?.startUpdatingLocation() self.createRegion(location: self.myLocation) //update M yLocation API if region.identifier.contains( AppConstants.WatchOverMe ) { TabBarController.isWOMReachDestinationAlertShown = false } } func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) { self.myLocation = manager.location self.createRegion(location: self.myLocation) } } extension AppDelegate { func applicationDidEnterBackground(_ application: UIApplication) { self.scheduleBackgroundTask() } func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { completionHandler(.newData) } func registerBGTask(){ BGTaskScheduler.shared.register(forTaskWithIdentifier: self.getBGTaskIdentifier(), using: nil) { task in self.handleBackgroundTask(task: task as! BGAppRefreshTask) } } func handleBackgroundTask(task: BGAppRefreshTask) { task.setTaskCompleted(success: true) } func scheduleBackgroundTask() { let request = BGAppRefreshTaskRequest(identifier: self.getBGTaskIdentifier() ) request.earliestBeginDate = Date(timeIntervalSinceNow: 10) // 30 second do { try BGTaskScheduler.shared.submit(request) } catch { print("Unable to schedule background task: (error)") } } func getBGTaskIdentifier()->String { let bundleId:String = AppInfoManager.shared.bundleId + ".locationBackgroundTask" return bundleId } func startLocationTrackingTimer() { self.stopLocationTrackingTimer() self.locationTrackingTimer = Timer.scheduledTimer(timeInterval: 1.0,target: self, selector: #selector(self.updateUserLocation),userInfo: nil,repeats: true) RunLoop.current.add(self.locationTrackingTimer!, forMode: .common) } func stopLocationTrackingTimer() { self.locationTrackingTimer?.invalidate() self.locationTrackingTimer = nil } @objc func updateUserLocation() { if self.isSocketActive { self.updateMyLocationAPI(fromRoam: false) } else { self.updateUserCurrentLocation() } } }
Posted Last updated
.
Post not yet marked as solved
2 Replies
417 Views
Which mode uses the least battery? The docs don't say much at all about the modes. default airborne automotiveNavigation fitness otherNavigation Some background is that they all result in location updates every 1s, I would gladly trade battery performance for less frequent updates.
Posted
by Wallman94.
Last updated
.