Can I integrate Timer along with liveUpdates(_:) in order to manipulate the frequency. Let say for example I need the user location ever 1 min. Is it possible to do so?
Maps and Location
RSS for tagBuild maps and location awareness capabilities into your apps.
Posts under Maps and Location tag
83 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I encountered a crash in iOS 17 related to CLBackgroundActivitySession, which appears to be due to misleading guidance in an Apple’s WWDC video.
Crash sample code: https://github.com/steve-ham/AppleLocationCrash
Simplified Reproduction Steps:
1. Open the GitHub sample app.
2. Archive and export (Distribute App -> Custom -> (Release Testing, Enterprise, or Debugging) -> Export).
3. Open the app.
4. Tap enableBackgroundLocation -> select Allow While Using App on the system popup.
5. Tap disableBackgroundLocation.
6. Go to the iOS home screen.
7. Wait for 10 seconds.
8. Reopen the app -> crash occurs.
The crash happens because setting CLBackgroundActivitySession to nil does not end the session, despite Apple’s guidance suggesting it should. Below is the exact quote from WWDC 2023, which explicitly states that both calling invalidate() or letting the object get destroyed (i.e., setting to nil) would end the session:
WWDC 2023 Discover Streamlined Location Updates (https://developer.apple.com/videos/play/wwdc2023/10180/)
“Before starting the updates, you should instantiate a CLBackgroundActivitySession object to start a new session. Note, we are assigning the session to self.backgroundActivity, which is a property and not to a local variable. And this is important because if we used a local variable, then when it goes out of scope, the object it holds would be deallocated, invalidating the session and potentially ending your app’s access to location. Then when we want to end our session, we can do that by sending the invalidate message or by letting the object be destroyed.”
I’ve submitted this to Apple for resolution but wanted to share this with the community. This misguidance has caused issues in my app’s release. If Apple could reply to confirm or provide clarification, it would be greatly appreciated.
P.S. Even a minimal implementation in viewDidLoad triggers the crash:
let session = CLBackgroundActivitySession()
print("session (session)")
Hi,
Have been trying to work with MapkitJS for a website, but I'm stumped on once basic capability: I want to be able to click on a point of interest, and perform some actions such as:
Get its coordinates
Attach an annotation to it (e.g. a callout)
In my code, PointOfInterest's are selectable:
map.selectableMapFeatures = [
mapkit.MapFeatureType.PointOfInterest,
];
But when I click on one, I do see the marker pop up but nothing else (which is not much help since there is no additional information in the marker itself). I see no event getting triggered that I can do something with.
I am using an event listener as follows:
map.addEventListener('single-tap', (event) => {
const coordinate = map.convertPointOnPageToCoordinate(event.pointOnPage);
console.log('Map tapped at:', coordinate);
console.log('Map tapped event:', event);
...
I guess I have to grab the Place ID somehow but I don't know how to.
Thanks for any help.
We have to draw polygons inside a MKMapView based on coordinates retrieved from external source.
It seems that MapKit does not behave correctly where polygons have single-vertex self-intersection.
Here it's a simple point list example (every element is a pair of latitude and longitude values):
[(0, 0), (20, 0), (10, 10), (20, 20), (0, 20), (10, 10), (0, 0)]
The next image shows the rendering issue.
But if the list is slightly changed in this way
[(0, 0), (20, 0), (10, 10), (20, 20), (0, 20), (15, 10), (0, 0)]
the issue disappears. The next image shows it.
So it's not a self-intersection and self-tangency problem, but we think single-vertex self-intersection is a buggy edge case for MapKit.
Right now we fixed this problem by finding the duplicated coordinates and applying a small offset (1e-8) to one of them, but it's a temporary solution and adds rendering delay.
The problem is not due to iOS versions, since iOS 17 and 18 have the same issue. Also it happens on simulators and real devices.
Here is the playground example, based mostly on the "Map Playground" template Xcode offers. If you run it without modifying it, the playground shows the "bugged" polygon. If you use notBugPoints instead of the default bugPoints for the polygon, the playground shows the "not-bugged" polygon.
import MapKit
import PlaygroundSupport
// Create an MKMapViewDelegate to provide a renderer for our overlay
class MapViewDelegate: NSObject, MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if let overlay = overlay as? MKPolygon {
let polygonRenderer = MKPolygonRenderer(overlay: overlay)
polygonRenderer.fillColor = .red
return polygonRenderer
}
return MKOverlayRenderer(overlay: overlay)
}
}
// Create a strong reference to a delegate
let delegate = MapViewDelegate()
// Create an MKMapView
let mapView = MKMapView(frame: CGRect(x: 0, y: 0, width: 800, height: 800))
mapView.delegate = delegate
// Configure The Map elevation and emphasis style
let configuration = MKStandardMapConfiguration(elevationStyle: .realistic, emphasisStyle: .default)
mapView.preferredConfiguration = configuration
// Create an overlay
let bugPoints = [
MKMapPoint(CLLocationCoordinate2DMake(0, 0)),
MKMapPoint(CLLocationCoordinate2DMake(20, 0)),
MKMapPoint(CLLocationCoordinate2DMake(10, 10)),
MKMapPoint(CLLocationCoordinate2DMake(20, 20)),
MKMapPoint(CLLocationCoordinate2DMake(0, 20)),
MKMapPoint(CLLocationCoordinate2DMake(10, 10)),
MKMapPoint(CLLocationCoordinate2DMake(0, 0))
]
let notBugPoints = [
MKMapPoint(CLLocationCoordinate2DMake(0, 0)),
MKMapPoint(CLLocationCoordinate2DMake(20, 0)),
MKMapPoint(CLLocationCoordinate2DMake(10, 10)),
MKMapPoint(CLLocationCoordinate2DMake(20, 20)),
MKMapPoint(CLLocationCoordinate2DMake(0, 20)),
MKMapPoint(CLLocationCoordinate2DMake(15, 10)),
MKMapPoint(CLLocationCoordinate2DMake(0, 0))
]
let polygon = MKPolygon(points: bugPoints, count: notBugPoints.count)
mapView.addOverlay(polygon)
// Frame our annotation and overlay
mapView.camera = MKMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(10, 10), fromDistance: 5000000, pitch: 0, heading: 0)
// Add the created mapView to our Playground Live View
PlaygroundPage.current.liveView = mapView
On iPhone, we can use iBeacon to wake up the APP in the background for Bluetooth scanning connection, now we want to port the function to AppleWatch APP, but the API related to iBeacon is not applicable on watchOS, does watchOS have a similar wake up mechanism?
We create new development maps for builders and developers. Is it possible for us to add the new streets and addresses to Apple Maps so that visitors can find these brand-new streets and addresses?
I have an application that uses geolocation to track the user’s location and trigger actions when the app is in either the foreground or background. Currently, it seems that region entry is not triggered unless an app like Maps (which actively uses location services) is opened. The location permissions are correctly set to “Always” with precise location enabled.
We are using geofencing to setup region and trigger actions when entering or leaving.
Is there something I’m missing in the configuration that could be preventing region monitoring from triggering properly when the app is in use or in background?
My app has been using MKLocalSearch.Request for keyword-based location searches, and it has worked smoothly for a long time. However, starting last Wednesday, I began receiving an error from MKLocalSearch.start: MKErrorDomain (error code 4).
This issue only occurs when the network environment is based in mainland China (where the API uses the Amap data source). When the network switches to other regions and other Apple Maps data source is used, the error does not occur.
Another complication is that the API doesn't always fail—certain keywords still work (for example, "Huawei").
Already filed a ticket in Feedback Assistant: https://feedbackassistant.apple.com/feedback/15544549
For some background, my app is a Flutter app and I have opened it in xcode to try the following, I can build and run it on a simulator from xcode as well.
I want to be able to simulate custom moving locations for my app. I tried going to Debug -> Simulate Location like online tutorials show but it is all greyed out.
I have location simulation enabled (I have tried changing the default location too):
Within the simulator itself I only have the predefined routes or a custom static location with no option for a moving location.
How can I simulate a custom moving location?
If it isn't possible is there anyway to simulate the location for a Mac app as I can build the Flutter app for Mac as well?
I am currently developing an application that requires access to GPS coordinates from photos on iOS. However, with the recent update to iOS 18 beta, I have encountered a challenge: I can only view photos within maps, and I am unable to access the GPS coordinates directly.
Could you please provide guidance on how to enable or retrieve GPS coordinates from photos in the current iOS 18 beta version? Any insights or resources you could share would be greatly appreciated.
Thank you for your assistance!
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?
Hi,
Where can I get more information on expected behaviour for the liveUpdates() configuration options, .default, .automotiveNavigation, .fitness, .automotive, .otherNavigation?
Looking for expected accuracy, frequency of updates, non/stationary transition, etc.
Thanks
Scrolling and zooming
I have two apps that utilize the Apple Maps and since I updated my xcode to use IOS18, some of the functionalities have either been missing or glitching, and when I roll back to IOS17.5, everything seems to work fine.
When I use MKMapView and use
mapView.isZoomEnabled = true
mapView.isScrollEnabled = true
Scrolling and zooming is still not working on IOS18 but IOS17.5 works fine.
Clicking on custom annotations
When I press on a custom annotation I add to the MapView, the gesture is sometimes recognized and most of the times not recognized. If I have 20 annotations, there is a possibility only 2 of them respond to tap gestures. Below is how I define the annotation.
Annotation("Pin", coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude), anchor: .bottom) {
Button(action: {print ("Pressed annotation"){
CustomPin()
}
}
I updated my phone 14 pro to ios 18 and I faced issue with GPS. it’s show me in next Country and after minutes or hours it’s moved to the correct location
how is it can fix it
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.
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.
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!
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!
We developed a app in which the I need the app to update the User's location even in background( even after terminating from the recent UI ),
Currently I am receiving the location updates when the user has kept the app in open and if minimised,
But I want that it should update the location even when it is removed from recent app (minimised UI)(after terminating the app)
Is it possible to do so.???
Hello everyone,
I’m experiencing an issue with App Clips Advanced Experiences and Apple Maps/Siri Suggestions. We have already contacted Apple Support before, but they are investigating the cause of this issue and it has not been resolved til date.
The App Clip is bundled with the main app and has been already available on the App Store for several months. The business running the app has several physical shops and wants to offer the App Clip to show up in Apple Maps and Siri Suggestions at each location.
The App Clip is correctly exposed in the AASA file, and it's also validated correctly by the AASA APIs available at https://app-site-association.cdn-apple.com/a/v1.
{
"applinks": {
"apps": [],
"details": [
{
"appID": "TEAMID.bundleid",
"paths": []
}
]
},
"appclips": {
"apps": [
"TEAMID.bundleid.Clip"
]
}
}
(with TEAMID and bundleid being the team and bundle identifiers of the app)
The App Clip is displayed correctly when loading the website and when scanning a QR code or App Clip code, but doesn't appear in the Maps app or in Siri suggestions.
We have set up the App Clip Advanced Experiences on the App Store Connect page of the app, and each URL has been linked to a physical shop. All URLs are in the "Received" state, so they should appear correctly on Maps.
Unfortunately, I don't see any "Order" button in Apple Maps at any location card. We tried with both iOS 17 and 16. According to feedbacks from people in the shops, they don't see the app suggested in the Siri Suggestions.
I have just submitted a Custom Action Link on Apple Business Connect for one of the shops, but without success: the App Clip doesn't appear.
Any idea why is this happening?