Maps & Location

RSS for tag

Learn how to integrate MapKit and Core Location to unlock the power of location-based features in your app.

Maps & Location Documentation

Post

Replies

Boosts

Views

Activity

Core Location always failing (kCLErrorLocationUnknown)
Hello. I’m trying to use Core Location Service on any application in Mac (Safari, Maps, Weather, Chrome with Core Location configuration, or just trigger the API with a standalone app) and it seems that all of them constantly fail to provide the geolocation of my device because of the same error (kCLErrorLocationUnknown). I'm using MacBook Pro (M3 Max) with Sonoma 14.7. I’m sure the apps have access in the settings and everything is in order except the Core Location response. I’ve tested the issue on multiple MacBooks and it reproduced 100% of the times on all of them. Did anyone encounter a similar issue?
0
0
261
Oct ’24
Background Task in iOS App
Hi, I am working on a React Native app and i want to have a latitude longitude of a user in every 15 minutes and want to do something like an api call with it. I want to keep continuing this no matter my app is in background, foreground or in killed state. Is there any way or method through which i can achieve this natively or using React Native?
1
0
207
Oct ’24
Standalone watchOS not displaying location authorisation dialog
This is a standalone SwiftUI app w/ watchOS 11. To make things simple, I'm using the new concurrent API, like that: for try await update in CLLocationUpdate.liveUpdates() { … } watchOS is supposed to show the auth dialog, but it doesn't show up, even though update.authorizationRequestInProgress is true. What could be the reason? (Note that I also tried with the procedural old CLLocationManager API, it doesn't work that way as well)
3
0
237
Oct ’24
GPS Icon Appears on App Launch Despite No CLLocationManager Usage – Need Help Tracing Cause
Hello everyone, I’m facing an issue with my iOS app where the GPS/location services icon appears in the status bar immediately when the app is launched, even though I’m not intentionally accessing location services at that point. Issue Summary: • GPS Icon Activation: When I launch my app, the GPS icon turns on. It turns off when the app is minimized or closed. • No Intentional Location Usage at Launch: I have ensured that no instances of CLLocationManager are created when the app is launched. What I’ve Tried So Far: 1. Checked Controllers and Related Classes: • Reviewed all the code for the controllers that are active at launch. • Verified that none of these controllers create instances of CLLocationManager or call location-related methods. 2. Commented Out startUpdatingLocation: • Commented out all calls to startUpdatingLocation throughout the entire project. 3. Ensured No CLLocationManager Instances at Launch: • Searched for any code that might instantiate CLLocationManager during app launch. • Confirmed that no such instances are being created. 4. Commented Out Google Maps SDK Configuration: • In AppDelegate, commented out the Google Maps SDK configuration, so it’s not initialized with the API key. • No map views (GMSMapView, MKMapView) are initialized or used when the app is launched. 5. Tested Location Permissions: • When I change the location permission for the app to “Never” in the Settings app, the GPS icon does not appear upon app launch. • This suggests that the app is accessing location services when it has permission, even though I haven’t explicitly requested it at launch. Objective: • Control GPS Activation: I want to ensure that the GPS does not turn on when the app is launched. I intend to activate location services only when needed later in the app. Request for Assistance: I’m seeking guidance on the following: 1. Debugging Techniques: • How can I trace the code that’s causing the GPS to turn on at app launch? • Are there tools or methods to identify hidden or indirect calls to location services? 2. Forcing Location Services Off at Launch: • Is there a way to programmatically prevent location services from activating during app launch? • Can I defer any implicit location service initialization until I explicitly enable it? 3. Potential Hidden Triggers: • Are there known scenarios where location services could be activated without direct use of CLLocationManager? • Could frameworks like Google Maps SDK trigger location services even if not fully initialized? 4. Additional Suggestions: • Any other insights or suggestions to prevent the GPS icon from appearing on app launch. Additional Information: • Third-Party Frameworks: • I have not removed third-party frameworks yet, as I wanted to check other possibilities first. • Open to the idea that a third-party framework might be causing this, but need guidance on how to confirm. • Code Availability: • I’m happy to provide specific code snippets if that would help diagnose the issue. Environment: • Xcode Version: Xcode 15.4, Xcode 16.0 • iOS Deployment Target: iOS 15.0 • Devices Tested: iPhone SE 2nd and 3rd gen, iPhone 15, iPhone 15 pro, iPhone 11 • Programming Language: Swift What I’m Looking For: • Assistance in tracing the cause of the GPS activation on app launch. • Suggestions on how to prevent location services from starting until explicitly needed. • Insights into any hidden triggers or indirect usages that might cause this behavior. Thank you for your time and assistance. Any help to resolve this issue would be greatly appreciated.
1
1
212
Oct ’24
Weather App
I keep getting severe weather warnings in CA but I’m in NY. I have checked my locations and I have no CA weather requests selected. I clicked on the alert and it said it was from weatherkit. How do I make these CA go away for good? Thanks!
3
0
234
Oct ’24
Iphone is deleting my messages automatically
I have checked the setting and it is and has always been set to forever when it comes to settings-messages-message history. Yet since I upgraded to ios 18.1, my messages have started to delete by themselves every other day or so. In the last week, I have had to go into the recently deleted and recovered the messages at least 3-4 times. It does not delete all my messages just random messages from whom I have messaged recently. I have message that have been there for at least 6 years and those are not deleting. Please help before I lose some valuable messages.
1
0
195
Oct ’24
MKLocalSearch for cities - How to uniquely identify results?
I'm using MKLocalSearch with resultTypes set to .address to search for cities. The search results don't include an ID for each city, which I need for database storage (which from my understanding is the only thing we can store). If I can't store the city name, country, and coordinates in my database, and I'm not allowed to use third-party data (like a pre-made list of cities with coordinates), what are my options for uniquely identifying and storing these city results? Any suggestions would be greatly appreciated.
0
0
185
Oct ’24
CLLocationUpdate.liveUpdates does not work after recovery from termination with insufficientlyInUse option
In iOS 18, we use CLLocationUpdate.liveUpdates to resume location updates after the app has been terminated. While the app successfully relaunches and I attempt to restart CLLocationUpdate.liveUpdates, the updates frequently come with the insufficientlyInUse flag set to true. At the same time, the locationUnavailable flag is false, but the location value remains nil. Could you clarify what the insufficientlyInUse option indicates and why the location updates are not returning valid data?
2
0
248
Sep ’24
Prevent pausing location updates on background when stationary?
Hello, I'm trying to receive location updates on background mode but it only lasts about 10 minutes then it stops when API detected the "isStationary" is true. Is there any way to continue receiving updates even when the device is stationary? Btw app is not terminated by the user. I'm using CLLocationUpdate.liveUpdates(.otherNavigation) API. CLBackgroundActivitySession is created before calling the liveUpdates. CLLocationManager: let manager: CLLocationManager = { let manager = CLLocationManager() manager.distanceFilter = kCLDistanceFilterNone manager.desiredAccuracy = kCLLocationAccuracyThreeKilometers manager.pausesLocationUpdatesAutomatically = false manager.activityType = .other manager.showsBackgroundLocationIndicator = true manager.allowsBackgroundLocationUpdates = true return manager }() Thank you!
3
0
416
Sep ’24
MKLocalSearch for cities not returning location identities
Hi fellow developers, I'm encountering an issue when using MKLocalSearch to search for cities. Here's my setup: I'm using MKLocalSearch with an MKLocalSearch.Request object. I've set the resultTypes to .address to focus on address results. The problem: When I receive the search response, it includes the locations as expected. However, these locations don't have an identity or alternative identities. Questions: Is this the expected behavior when searching for cities? Without an identity, how can I uniquely identify and store these city results in my database? Would it be appropriate to store the city name, country, and coordinates instead? Thanks in advance!
0
0
211
Sep ’24
CLLocationManager didUpdateLocations called in an infinite loop on macOS Sequoia, despite no startUpdatingLocation called
In my app, I need a one-time location update, which I do with CLLocationManager’s requestLocation(). On iOS, it works fine, but on macOS Sequoia, the CLLocationManagerDelegate’s didUpdateLocations function is called indefinitely in the loop, until I call stopUpdatingLocation() on a manager. This should not be necessary unless I was calling startUpdatingLocation (which I am not), and seems like a newly introduced bug in Sequoia (or Xcode 16). So, just a heads-up to everyone, it's necessary to call stopUpdatingLocation() after obtaining the location (or on error).
1
0
262
Sep ’24
How to find coordinates for Map Overlay placement
Hello everyone - I created a navigation app that uses a map overlay for finite spaces such as a zoo. I get these overlays created by a designer in .PNG - the designer creates the overlays and then puts a square or rectangle box around the overlay because it needs to be placed in 9 pieces making it easier to render when user zooms in/out... I used to have my Swift devs place the overlay using the correct coordinates that were given by a single person, but we never found out exactly how they did it - and now I can no longer contact the dev. Can anyone help me by telling me how I can get the coordinates (I am thinking that any opposite vertices would do - and maybe the center point?). I also have a few other questions: a. Is .SVG best to use for map overlays? b. Should we continue to chop into 9 pieces for faster rendering or is there a better way to do this in MapKit (we have been doing this for 4 years, maybe there is a better way) I would be so thankful for any help. Best, Michael
2
0
250
Sep ’24
Apple Maps cannot route to Latitude & Longitude
I've started getting reports of this today and I am able to replicate it on my end but looking to see if anyone else can verify or if it's possibly regional to me (Canada). In Apple Maps (iOS or macOS), if you search a latitude and longitude -- for example: "49.110,-112.110" and search, it centers on the location as it always has and shows the "Directions" button. When you tap the directions button, I get "A route can't be shown because of a problem connecting to the server.". Alternatively, if you pass the coordinate in via Apple Maps URL (https://maps.apple.com/?daddr=49.110,-112.110) it will route but the route is no longer to those specific coordinates, Apple Maps alters them to some nearest known entity (in this case, the RM of Warner County). If you compare the suggested route end destination with the search results for specifically entering the coordinates, you will see they are different locations and mapping routes are not actually taking you to the coordinates anymore. In the last photo attached, the arrow points to where "49.110,-112.110" is actually located which tapping the "Directions" button cannot figure out a route because of a server issue. If you pass it in via URL, it changes the destination coordinates and begins a route quite a ways away from the intended coordinate. The problem started happening either this morning or last night. Can anyone else confirm this happens to them? Thanks, Mike
14
3
2.0k
May ’24
MKScaleView doesn't update changing area programmatically
I have a MKMapView with a MKScaleView. If I visualise a generic map I have the scale in km. When I change the MKMapRect using visibleMapRect, the scale doesn't change. If I use setVisibleMapRect(_ mapRect: MKMapRect, animated animate: Bool), the scale change but not to the correct one. For example, it shows a scale saying one inch corresponds to 250 m while it is 150 m. The same issue of I use MKCoordinateRegion. Instead, if I zoom in or zoom out pinching on the map, the scale updates correctly. Am I doing something wrong? How can I fix this? Sample code: import UIKit import MapKit let CORNER_RADIUS: CGFloat = 8.0 let METERS_PER_MILE: Double = 1609.344 class PIAnnotation: NSObject, MKAnnotation { var coordinate: CLLocationCoordinate2D private(set) var title: String? private(set) var subtitle: String? init(location: CLLocationCoordinate2D, title: String? = nil, subtitle: String? = nil) { coordinate = location self.title = title self.subtitle = subtitle } } class PISimpleMapView: MKMapView { private let HALF_MAP_SIDE_MULTIPLIER: Double = 1.4 private let pinIdentifier = "pinIdentifier" private var scaleView: MKScaleView? typealias PinAnnotationView = MKMarkerAnnotationView // MKPinAnnotationView required init?(coder: NSCoder) { super.init(coder: coder) inizialize() } override init(frame: CGRect) { super.init(frame: frame) inizialize() } func inizialize() { layer.cornerRadius = CORNER_RADIUS register(PinAnnotationView.self, forAnnotationViewWithReuseIdentifier: pinIdentifier) addScale() } private func addScale() { let scale = MKScaleView(mapView: self) scale.translatesAutoresizingMaskIntoConstraints = false scale.scaleVisibility = .visible // always visible addSubview(scale) let guide = safeAreaLayoutGuide NSLayoutConstraint.activate([ scale.leftAnchor.constraint(equalTo: guide.leftAnchor, constant: 16.0), scale.rightAnchor.constraint(equalTo: guide.centerXAnchor), scale.topAnchor.constraint(equalTo: guide.topAnchor), scale.heightAnchor.constraint(equalToConstant: 20.0) ]) scaleView?.removeFromSuperview() scaleView = scale } func displayPinOnMap(location: CLLocation) { let annotation = PIAnnotation(location: location.coordinate, title: "Sample", subtitle: nil) addAnnotation(annotation) // Position the map so that all overlays and annotations are visible on screen. visibleMapRect = visibleArea(from: annotation) // setVisibleMapRect(visibleArea(from: annotation), animated: true) // region = MKCoordinateRegion(visibleArea(from: annotation)) } private func visibleArea(from annotation: PIAnnotation) -> MKMapRect { let annotationPoint = MKMapPoint(annotation.coordinate) return MKMapRect(x: annotationPoint.x - HALF_MAP_SIDE_MULTIPLIER * METERS_PER_MILE, y: annotationPoint.y - HALF_MAP_SIDE_MULTIPLIER * METERS_PER_MILE, width: HALF_MAP_SIDE_MULTIPLIER * 2.0 * METERS_PER_MILE, height: HALF_MAP_SIDE_MULTIPLIER * 2.0 * METERS_PER_MILE) } }
5
0
463
Aug ’24