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

Posts under Maps & Location subtopic

Post

Replies

Boosts

Views

Activity

When should I convert coordinates to GCJ02?
Our backend management system uses Google for Location, and Apple Maps is just one of the solutions in our map component. When should I convert coordinates to GCJ02? Maybe you would say that when you are in mainland China? BUT NOT AT ALL! What if the user does not enable location permission? What if the user has not inserted a SIM card? Or not Chinese SIM card but location in China? OR the user location in China, But use VPN with en overseas IP? All solutions are not perfect, unless you open the API to developers and tell us whether Apple Maps currently uses the wgs84 coordinate system or gcj02, which is the most reliable.
1
0
92
Jun ’25
Location via GPS jumps
We have a that relies on accurate GPS location but we’ve noticed that every now and then the location ‘jumps’ a few hundred meters to a different location but reports horizonal accuracy less than 10m. we think the device is picking up a rough location from a local WiFi rather than internal gps sensors. can we a) disable WiFi location Updates? b) identify WiFi location Updates? thank You
7
0
219
2w
LookAroundPreview navigation not working on macOS
The code below using LookAroundPreview works fine on iOS (showing the preview image with a button saying "Look Around" at the top to enter full screen with navigation), but on macOS (15.3) there is no button and no way to navigate the view. Is this a bug or is there something I need to do differently on macOS? I have also tried using AppKit with MKLookAroundViewController and I don't seem get the button to launch full screen there either. import SwiftUI import MapKit struct ContentView: View { var body: some View { LookAroundPreviewView(coordinate: CLLocationCoordinate2D(latitude: 37.33182, longitude: -122.03118)) .frame(width: 300, height: 200) } } struct LookAroundPreviewView: View { let coordinate: CLLocationCoordinate2D @State private var scene: MKLookAroundScene? @State private var errorMessage: String? var body: some View { Group { if scene != nil { LookAroundPreview(scene: $scene, allowsNavigation: true) } else if let errorMessage = errorMessage { Text("Error: \(errorMessage)") .foregroundColor(.red) } else { ProgressView("Loading Look Around Preview...") } } .task { do { let request = MKLookAroundSceneRequest(coordinate: coordinate) let fetchedScene = try await request.scene scene = fetchedScene } catch { errorMessage = error.localizedDescription print("Error loading Look Around scene: \(error)") } } } }
1
0
335
Feb ’25
[iOS] Location data no longer updating consistently after updating the app from old version
I am developing an iOS app that uses CLLocationManager to collect location continuously in both foreground and background. But it has the following 4 issues and I don’t understand why: After a while of not using the app, I can not get location updates regularly. Even after that, I go into the app more often or even turn OFF and turn ON the permission again, but the problem still doesn’t improve until I reinstall the app. Previously, I used SilentLog SDK to collect location. Since the cost was quite high, we developed our own SDK that also handles location tracking. After updating the app from the old version using SilentLog SDK to the new version using my own SDK, I can not get location updates regularly. However, when I reinstalled the app, it worked perfectly. It seems that apps downloaded from TestFlight can get location more continuously than apps downloaded from the App Store We sometimes encounter this error in the logs: Error Domain=kCLErrorDomain Code=0 “(null)” I think my app was not terminated in the background because I still collect location but it is not as frequent. I want to know if Apple has any mechanism to prevent such apps from getting location data continuously? I use CLLocationManager with the following configuration: self.locationManager.distanceFilter = 20 self.locationManager.desiredAccuracy = kCLLocationAccuracyBest self.locationManager.allowsBackgroundLocationUpdates = true self.locationManager.showsBackgroundLocationIndicator = false self.locationManager.pausesLocationUpdatesAutomatically = false I also filter the location updates using: guard let location = locations.last else { return } guard location.horizontalAccuracy <= 100 else { return } guard location.speedAccuracy >= 0 else { return } I use a background task to wake up the device every 15 minutes, and I also use silent push notifications in a similar manner. Each time the task is executed, I usually call stopLocation and then startLocation again. This happens quite frequently — will it have any impact or cause any issues?
0
0
118
May ’25
How to update business information on Apple Maps Ukraine?
Hello everyone, I need help updating business information on Apple Maps for locations in Ukraine. Unfortunately, the usual methods, like "Report an Issue" in the Maps app or using Apple Business Connect, don’t seem to be working properly for Ukrainian businesses. Many locations have outdated or missing details, which is frustrating for both business owners and customers. Given the current situation, keeping information accurate is more important than ever. Has anyone successfully updated business listings in Ukraine recently? If so, could you share the process or any contacts that might help? Any advice would be greatly appreciated! Thanks in advance!
1
0
253
Mar ’25
How can you determine if the map tiles in MapKit have successfully loaded?
We are developers of a golf app designed to assist golfers on the course. A key feature of our app is displaying a map of each hole, and we are currently transitioning to using MapKit and camera functionalities for this purpose. However, we are encountering issues with the downloading of map tiles when using the default satellite imagery. We have tried several approaches to diagnose the issue: We have tried several things to diagnose the issue: We implemented the mapViewDidFailLoadingMap delegate method. But it is inconsistent, sometimes triggering offline errors even when map tiles are cached. We implemented, the mapViewDidFinishRenderingMap method, but it always returns false when offline or you won't get the callback. Which doesn't let us know that rendering tiles has failed. We would appreciate your guidance on the following specific questions: Does MapKit provide a way to confirm if a map tile has fully loaded? Is there a method to detect if a portion of the map hasn't loaded or if a tile request has failed? Can we determine whether a map tile is cached, and if so, how long it will remain cached, similar to Cache-Control HTTP headers? Is there a way to trigger the preloading of map tiles when we know the user has a good internet connection? Please see the sample project for steps to reproduce the issue. Thank you for any assistance!
3
0
390
Jan ’25
Apple Maps Server API Geocoding returns empty results for Japanese addresses with lang: 'ja-JP'
Hi, I'm using the Apple Maps Server API (/v1/geocode) to retrieve geocoding results for Japanese addresses. Until recently, requests like the one below returned correct results: GET https://maps-api.apple.com/v1/geocode?q=東京都千代田区千代田1-1&lang=ja-JP Authorization: Bearer <valid JWT> But now, the response is always: { "results": [] } However, when I use the same address with lang: en-US, it returns valid coordinates: GET https://maps-api.apple.com/v1/geocode?q=1-1 Chiyoda, Chiyoda-ku, Tokyo=en-US "東京都千代田区千代田1-1" is a Japanese address, and "1-1 Chiyoda, Chiyoda-ku, Tokyo" is the same address written in English. My Questions: Has there been a recent change to the geocoding behavior for Japanese addresses when lang: ja-JP is used? Does the lang parameter affect not only the response language but also the internal parsing logic? Is this a known issue or limitation? The access token is valid and I'm getting a 200 OK response, but results is always empty with lang: ja-JP. Thanks for your help!
0
0
97
Jul ’25
Beacon Exits region and is unavailable for extended periods
Hi, We are using beacon ranging methods to detect beacon in foreground and background in our app. We are using beacon's UUID, major and minor values to create a beacon region and then calling locationManager.startRangingBeacons to range beacons. We listen for beacon updates via the didRangeBeacons delegate method to get beacon data emitted. However, we've observed some inconsistent behavior: The beacon region frequently reports exit events even when the device is within close proximity (approximately 1.5 to 2 meters). There are instances where no beacon updates are received for extended periods (up to 15–20 minutes), despite the beacon being nearby. Generally, The distance between the device and the beacon is approximately 1.5 - 2 meters. What could be the reason for this behaviour and how can we avoid it and continuously receive beacon updates when the beacon is near without any delay? Thanks
1
0
11
1d
Location Error
I started getting a location error recently. I've never seen this error before and it began happeing randomly. Here is the breakpoint. (if let locationManager........) var currentLocation: Result<CLLocation, Error> { get { #if DEBUG return .success(CLLocation(latitude: CLLocationDegrees(exactly: 0)!, longitude: CLLocationDegrees(exactly: 0)!)) #else if let locationManager = self.locationManager { return locationManager.currentLocation } return .failure(LocationError.unknown) #endif } } I've tried everything I can think of to fix the issue. It has an issue getting the users location when logging in. I've made no changes to the code and everything has worked for years. The bug reports show nothing. I've tried re-installing Xcode, rebuilding the pods etc. I've tried everything that you would normally do in this situation.
1
0
443
Nov ’24
What are possible failures when using CLLocationUpdate.Updates AsyncSequence
Hello, I'm currently migrating my app location service to use the new CLLocationUpdate.Updates. I'm trying to understand what can fail in this AsyncSequence. Based on the previous CLError, I thought authorisation was one of them for example but it turns out that this is handled by the CLLocationUpdate where we can check different properties. So, is there a list of errors available somewhere? Thanks Axel, @alpennec
2
0
406
Dec ’24
Geofencing with CLMonitor Does Not Work After User-Initiated Task Kill
I have implemented geofencing using CLMonitor. The implementation follows this general structure: private var monitorTask: Task<Void, Never>? private var backgroundSession: CLBackgroundActivitySession? func start() async { backgroundSession = CLBackgroundActivitySession() monitorTask = Task { do { let monitor = await CLMonitor("monitor") for try await event in await monitor.events { handleEvent(event: event) } } catch {} } } func addSpot() async { let monitor = await CLMonitor("monitor") let center = CLLocationCoordinate2D(latitude: 0, longitude: 0) let condition = CLMonitor.CircularGeographicCondition(center: center, radius: 100) await monitor.add(condition, identifier: "sample-1") } When the app is not task-killed, the code inside handleEvent executes as expected. However, after a user-initiated task kill, the functionality does not work properly.
2
0
453
Dec ’24
Background location tracking on iPad fails
My app needs to track background location for a period of several hours while the user is using it, and we want to allow the user to switch apps or lock their phone while this is happening. We don't need to track location permanently and because of this, we don't want to request the "Always allow" permission. The app requests "While in use" permission and it has the "Location updates" background mode enabled. The CLLocationManager has 'allowsBackgroundLocationUpdates' set to true, 'pausesLocationUpdatesAutomatically' false, kCLLocationAccuracyBest, kCLDistanceFilterNone, and .fitness for the activity type (we expect the user to be walking). The app also initializes a CLBackgroundActivitySession while it is tracking location and invalidates it when done. When I test this combination on my iPhone, it works fine. I get location tracking in the background for as long as I need it, regardless of what else I do with the phone. However, my customer says it doesn't work for him. He is using a Wifi-only iPad with an external GPS receiver called "BadElf GPS Pro". He says that the external GPS receiver works fine with other apps on his iPad. With my app, he gets background location tracking only for a short time, and then it stops. The app does monitor the "locationManagerDidPauseLocationUpdates" callback and posts a local notification if it gets called, but it doesn't get called. I've also confirmed with him that he is not force-quitting the app and the app is not otherwise being terminated by iOS. Is there something I'm missing?
3
0
567
Feb ’25
Detecting Driving State with Core Motion Framework - Automotive Accuracy Issues
I am working on an iOS app where I need to detect when a user starts and stops driving using the Apple Core Motion framework. I've implemented the following MotionActivityManager class to handle activity updates and display the detected states in a SwiftUI view. While I can accurately detect "Stationary" and "Walking" states, detecting the "Driving" (Automotive) state has been unreliable. The accuracy often fails, and the framework frequently misclassifies driving as other states like "Unknown" or "Walking." Here's the implementation: @Published var motionStates: [MotionState] = [] @Published var startDate: String = "" @Published var confidence: String = "" init() { setupDefaultStates() startActivityUpdates() } private func setupDefaultStates() { motionStates = [ MotionState(label: "Stationary", value: false), MotionState(label: "Walking", value: false), MotionState(label: "Running", value: false), MotionState(label: "Automotive", value: false), MotionState(label: "Cycling", value: false), MotionState(label: "Unknown", value: false) ] } func startActivityUpdates() { guard CMMotionActivityManager.isActivityAvailable() else { print("Motion activity is not available.") return } motionActivityManager.startActivityUpdates(to: .main) { [weak self] motion in guard let self = self, let motion = motion else { return } DispatchQueue.main.async { self.updateProperties(with: motion) } } } private func updateProperties(with motion: CMMotionActivity) { motionStates = [ MotionState(label: "Stationary", value: motion.stationary), MotionState(label: "Walking", value: motion.walking), MotionState(label: "Running", value: motion.running), MotionState(label: "Automotive", value: motion.automotive), MotionState(label: "Cycling", value: motion.cycling), MotionState(label: "Unknown", value: motion.unknown) ] startDate = dateFormatter.string(from: motion.startDate) switch motion.confidence { case .low: confidence = "Low" case .medium: confidence = "Medium" case .high: confidence = "High" @unknown default: confidence = "Unknown" } } } struct MotionState: Identifiable { let id = UUID() let label: String let value: Bool } struct ContentView: View { @StateObject private var motionManager = MotionActivityManager() var body: some View { ScrollView { VStack(spacing: 16) { ForEach(motionManager.motionStates) { state in LabelView(label: state.label, value: state.value ? "True" : "False") } LabelView(label: "Confidence", value: motionManager.confidence) } .padding() } .onAppear { UIApplication.shared.isIdleTimerDisabled = true motionManager.startActivityUpdates() } .navigationTitle("Motion Activity") } } Issues: The motion.automotive state is often not detected accurately. The confidence level remains low for the automotive state, even when the device is clearly in a car. How can I improve the detection accuracy of the "Driving" state using the Core Motion framework?
1
0
432
Jan ’25
Inquiry About Background Permission Issue in My App
I am writing to address a concern regarding the background permission functionality in my app, which is critical for ensuring user safety as they navigate various terrains. This feature also enables users to smoothly record their navigation tracks for review after their activities. Recently, I've noticed that this functionality is not working as seamlessly as before. Additionally, I observed that the app is not categorized under 'health and fitness'—could reclassifying it improve background activity? Before I delve into a detailed code review, I wanted to check if this issue might be related to sync or settings on the App Store side, such as permission configurations, app updates, or other related factors. Or, is it more likely an issue stemming from the app’s codebase?
1
0
443
Jan ’25
Remove WeatherKit from existing app
One of my apps includes a free weather forecast using WeatherKit. Recently, it started to get more downloads and almost reached the limits of the free tier. I've removed the forecast in newer versions but there's still a substantial amount of users who do not update their apps. Is it possible to somehow remove the capability from existing apps? Thank you!
1
0
80
Jun ’25
CLBackgroundActivitySession Crash Issue - Misleading Apple Guidance
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)")
2
0
757
Nov ’24
Re-enabling Background Location Services When Reconnecting to a Bluetooth Device
Hi all, We’re running into a challenge with our iOS app DriveSmarter, which uses background location updates when connected to a physical Bluetooth device (e.g., dash cam, radar detector). For battery efficiency, we disable location services in the background when no device is connected. The problem we’re now facing is: How can we programmatically re-enable location services when a Bluetooth device reconnects while the app is still in the background? From what I understand, Core Location doesn’t allow re-enabling background location updates unless the app returns to the foreground. But our core use case requires this to happen seamlessly in the background when the user starts driving and the device connects again. To clarify: We stop location updates when the device disconnects. We want to resume location updates only when the device reconnects, even if the app is still in the background. Manually bringing the app to the foreground is not a reliable or user-friendly option. So my questions: Is it possible to programmatically restart background location services upon a Bluetooth connection event while staying in the background? If not, are there any best practices or Apple-recommended alternatives to achieve a similar result? Any guidance, patterns, or creative solutions would be greatly appreciated! Thanks in advance
1
0
78
Jun ’25