Hi everyone!
I’m a new developer diving into my first Apple Watch project, and I’m really excited to get started! This app relies heavily on using the most precise location data possible.
Could anyone point me to some official documentation or helpful resources on how to achieve high-accuracy location tracking specifically for watchOS? Any tips or best practices would also be greatly appreciated!
Thanks in advance for your help!
Maps & Location
RSS for tagLearn how to integrate MapKit and Core Location to unlock the power of location-based features in your app.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
We have an application. We are monitoring the fence event. We are using 'startMonitoringForRegion' API. but we are not getting any fence event.
Steps
Create a fence using 'startMonitoringForRegion' API BG on APNS trigger.
initial fence state 'didDetermineState' not received.
From Syslogs we can see OS has detected but event is not given to Application
We are compiling code using SDK18.0
Error **
locationd Fence: LAC monitoring is not sufficient for /
ocationd Fence: no allowing wifi monitor for, 400.0, fence
Feedback Ticket ID: FB17250308
Syslogs Snippet:
debug 2025-04-15 12:45:40.890193 -0500 locationd FenceCal: combine non-fine non-large fence, distance, 0.0, /
//OS detetected fence state
default 2025-04-15 12:45:44.706232 -0500 locationd Fence: fenceUpdate, , bundle, , type, GPS , loc, 33.1171776, -96.6606076, acc, 19, distance, 17, tech, LC...+, trans, 0, state, 0, cont, 1, fence, 33.11728835, -96.66048288, 1011.0, 766431742.6, sCount, 0, 0, trig, 0, 3, sinceLastLoc, 10.0, events, 0x00001810, status, (Inside) => (Inside) , settled state, (Unknown) ==> (Unknown), cantShiftButNeedTo, 0, sinceLastTransition, -1.0, significant, 0, loi, 0, lastProximityStateTimestamp, -1.000000, lastProximityState, 0, lastApproachingState, 0
//
debug 2025-04-15 12:45:44.706247 -0500 locationd Fence: LAC monitoring is not sufficient for /
//
debug 2025-04-15 12:45:44.706263 -0500 locationd Fence: no allowing wifi monitor for, 400.0, fence, Fence, []//, latitude, 33.11728835, longitude, -96.66048288, refFrame, 0, distance, 1011.0, eFistance, 1011.0, lDown, -1.0, time, 766431742.6, ctime, -1.0, flags, EX------, key, -1506186373, throttled, N, polygon, 0, envType, 2, locType, 0
I have a marine navigation app which displays GPS quality information when receiving NMEA message from an external GPS. These include the number of satellites and Horizontal Dilution of Precision (HDOP).
As far as I can see, the only additional information available through location services (for devices with built in GPS) is horizontal and vertical accuracy.
Am I missing anything? Also does anyone know how horizontal accuracy is derived from HDOP?
Hi,
I am creating a Driving Behaviour Monitoring app in which I range beacons and I require location updates in foreground, background and in terminated state all the time.
I am using CLServiceSession with "Always Authorisation" to get location events. I create CLServiceSession object in the foreground and start monitoring driving and then re-create it when the app is relaunched after termination. Doing this works fine.
But sometimes when app is terminated and is not opened again, the app runs on its own even when the device is stationary ( I can see the app is using Location in the Control Centre) and after that Location updates are not received and I am not able to track the driving behaviour. I tried to add diagnostics to know the cause and found "Insufficiently In Use" and then "Service Session Required" in the diagnostics.
It would be of great help if the proper usage of CLServiceSession is provided.
Important Question: When does the CLServiceSession gets invalidated or destroyed that was created when the app was in foreground ? What happens to the CLServiceSession which was created in the foreground if the app is not opened for long duration, let's say a day or two?
I'm trying to create a link from a restaurant annotation on a map in my app (created using MapKit) that will open the Apple Maps app on an iphone. I've been using the Restaurant name, telephone number, and coordinates and cannot get applemaps to open the enhanced page (which contains photographs and customer reviews and is much more descriptive than the page that is opening, which only shows the location on a map with the phone number and coordinates. It is not that descriptive, and I'm trying to create a request that will make it very easy to jump back and forth between my app and the enhanced page on apple maps. here's what I'm using in my request: " private func openInAppleMaps() {
let coordinate = CLLocationCoordinate2D(latitude: restaurant.latitude, longitude: restaurant.longitude)
let placemark = MKPlacemark(coordinate: coordinate)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = restaurant.name
if let phone = restaurant.telephone1 {
mapItem.phoneNumber = phone
}
mapItem.openInMaps(launchOptions: [MKLaunchOptionsShowsTrafficKey: true])
}
}" the entire file is attached. Any help or advice would be much appreciated.
RestaurantCallOutBox.swift
Topic:
App & System Services
SubTopic:
Maps & Location
mapView.showsTraffic=true
mapView.showsScale=true
mapView.showsCompass=true
mapView.showsUserLocation=true
mapView.showsBuildings=true
mapView.showsLargeContentViewer=true
hi,guy,please help to see this problem,thankyou,the mapkit api support some showsfunction,but I can not find how to show the exit of subway in my own app,but the map app of appple shows the exit of the subway,so how can I show the exit of the subway stations by using mapkit
I need some clarification on what is supposed to happen if the "allowsBackgroundLocationUpdates" flag on CLLocationManager is set to true, and only the "While in Use" permission has been given.
The customer I'm working with thinks that this combination should allow the app to receive location updates in the background indefinitely, as long as the app was in the foreground when we started receiving them.
What we've experienced is inconsistent. App updates do continue when the screen locks and in some cases when we switch to another app, but often they do not.
Our app doesn't require location updates 24/7, it requires them for a period of time when the user is performing an activity. The user starts and stops the activity in the app, and the activity might last up to a couple of hours. Can we do this using "While in Use" or do we need to request "Always" ?
Topic:
App & System Services
SubTopic:
Maps & Location
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
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?
Topic:
App & System Services
SubTopic:
Maps & Location
Tags:
Maps Web Snapshots
Health and Fitness
Core Location
Background Tasks
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?
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?
Hello everyone,
I'm doing some work on validating some data to do with the zpseed functionality around corelocations, i've read up on the speedaccuracy field but the wording doesn't make sense to me. It says if its a positive number it is plus or minus the value in the zspeed column so would this be for example zspeed of 35 mps with an accuracy of 3 mps would it be 32 mps 38 mps or is it a range? so would it be anywhere between 32-38 mps. Or is it just plus or minus the 3mps and if this is the case how would it be worked out if its plus or minus when all the numbers will be a positive numbers as any negative numbers are deemed inaccurate ?
Hello, I have noticed that some users have modified their real location through an app called "MGU" to bypass my app's security checks. I want to know how to protect my app and detect users using virtual location. I have reproduced the process of virtual positioning here:
Insert a plug-in through the interface at the bottom of the phone and connect it via Bluetooth on the phone
Set the desired positioning target on the "MGU" app
Turn off your phone's WiFi, network, and location for 10 seconds, then turn it back on
At this point, virtual positioning is successful.
Please assist me in troubleshooting this issue and inform me of the principle of implementing virtual positioning in this app and how to prevent it.
The following is the screen recording of virtual positioning operation:
https://flowus.cn/share/145b3232-26c3-4ea3-b3ff-4aad1495eb4d
The other day I was playing with iBeacon and found out that CLBeaconIdentityConstraint will be deprecated after iOS 18.5. So I've written code with BeaconIdentityCondition in reference to this Apple's sample project.
import Foundation
import CoreLocation
let monitorName = "BeaconMonitor"
@MainActor
public class BeaconViewModel: ObservableObject {
private let manager: CLLocationManager
static let shared = BeaconViewModel()
public var monitor: CLMonitor?
@Published var UIRows: [String: [CLMonitor.Event]] = [:]
init() {
self.manager = CLLocationManager()
self.manager.requestWhenInUseAuthorization()
}
func startMonitoringConditions() {
Task {
print("Set up monitor")
monitor = await CLMonitor(monitorName)
await monitor!.add(getBeaconIdentityCondition(), identifier: "TestBeacon")
for identifier in await monitor!.identifiers {
guard let lastEvent = await monitor!.record(for: identifier)?.lastEvent else { continue }
UIRows[identifier] = [lastEvent]
}
for try await event in await monitor!.events {
guard let lastEvent = await monitor!.record(for: event.identifier)?.lastEvent else { continue }
if event.state == lastEvent.state {
continue
}
UIRows[event.identifier] = [event]
UIRows[event.identifier]?.append(lastEvent)
}
}
}
func updateRecords() async {
UIRows = [:]
for identifier in await monitor?.identifiers ?? [] {
guard let lastEvent = await monitor!.record(for: identifier)?.lastEvent else { continue }
UIRows[identifier] = [lastEvent]
}
}
func getBeaconIdentityCondition() -> CLMonitor.BeaconIdentityCondition {
CLMonitor.BeaconIdentityCondition(uuid: UUID(uuidString: "abc")!, major: 123, minor: 789)
}
}
It works except that my sample app can take as long as 90 seconds to see event changes. You would get an instant update with an fashion (CLBeacon and CLBeaconIdentityConstraint). Is there anything that I can do to see changes faster? Thanks.
I'm trying to scan for Beacon's in a visionos app
iBeacon detection via CoreLocation (like CLBeacon or CLBeaconRegion) isn't supported on visionOS, so I went for CoreBluetooth + Manual Beacon Parsing
Problem is I don't get my beacons scanned, only the other bluetooth devices
central.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey:true])
what should I do?
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.
Topic:
App & System Services
SubTopic:
Maps & Location
Tags:
MapKit
Maps and Location
Apple Maps Server API
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
Topic:
App & System Services
SubTopic:
Maps & Location
Hello,
I’ve done a lot of testing of location services running in background with various settings, but in all scenarios location updates pause after a couple of hours, especially overnight In sleep mode.
My app, for personal safety, requires regular location updates to 5m accuracy every minute. The only solution I have found is to keep the app in foreground.
Location always stops updating. Background mode stops updating. Live location services stops updating.
Is there a solution I may have missed other than keeping app in foreground?
thank you,
Brendan
My organization, Los Angeles Pierce College, rents space to "Topanga Vintage Market", which is a monthly weekend swap meet operation.
Apple Maps shows the location as roughly 34.18715° N, 118.58058° W. However, this is the location of the campus Child Development Center, which provides child care services and is not open during the hours of the Topanga Vintage Market.
The actual location should be in the adjacent large parking lot, roughly 34.18740° N, 118.57782° W. They do not have a physical building.
How do I get this resolved? I am putting a campus mapping application into the App Store real soon now.
There is also an entry for "ALC Taco Truck" about 34.18533° N, 118.57349° W, which as far as I know has not been on campus since Covid.
Thanks in advance for any guidance you can provide.
Topic:
App & System Services
SubTopic:
Maps & Location
Tags:
MapKit JS
MapKit
Maps and Location
Apple Maps Server API
I'm experiencing app crashes when calling the CLMonitor initialization function:
let monitor = await CLMonitor("my_monitor")
According to WWDC 2023: Meet Core Location Monitor, when creating a CLMonitor object with the same identifier, it should access the existing monitor without any mention of app crashes or buggy behavior.
However, in my actual testing, attempting to create a CLMonitor object with the same identifier immediately causes an app crash.
Here's part of the crash log:
Last Exception Backtrace:
0 CoreFoundation 0x19c4ab21c __exceptionPreprocess + 164 (NSException.m:249)
1 libobjc.A.dylib 0x199945abc objc_exception_throw + 88 (objc-exception.mm:356)
2 Foundation 0x19b7a9670 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 288 (NSException.m:252)
3 CoreLocation 0x1aa25cbb4 +[CLMonitor _requestMonitorWithConfiguration:locationManager:completion:] + 516 (CLMonitor.mm:516)
4 libswiftCoreLocation.dylib 0x22bf6085c CLMonitor.init(_:) + 488 (CLMonitor.swift:280)
5 libswiftCoreLocation.dylib 0x22bf604b9 <deduplicated_symbol> + 1
6 MiniPlengi 0x106372ec9 closure #1 in static CLMonitor.loplatMonitor.getter + 1 (CLMonitor+Extensions.swift:31)
7 MiniPlengi 0x1062ce325 0x106290000 + 254757
8 MiniPlengi 0x1062f6a29 specialized thunk for @escaping @isolated(any) @callee_guaranteed @async () -> (@out A) + 1 (/<compiler-generated>:0)
9 MiniPlengi 0x1062ce325 0x106290000 + 254757
10 libswift_Concurrency.dylib 0x1a7f75241 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1 (Task.cpp:537)
Furthermore, even though I've written code to create CLMonitor objects based on a singleton structure to handle these crash cases, the app still crashes:
extension CLMonitor {
static var loplatMonitor: CLMonitor {
get async {
struct Static {
static var monitor: CLMonitor?
static var initializationTask: Task<CLMonitor, Never>?
}
// If already initialized
if let monitor = Static.monitor {
return monitor
}
// If there's an initialization task in progress, wait for its result
if let task = Static.initializationTask {
return await task.value
}
// Create new initialization task
let task = Task {
let monitor = await CLMonitor("my_monitor")
Static.monitor = monitor
Static.initializationTask = nil // Clean up task after completion
return monitor
}
Static.initializationTask = task
return await task.value
}
}
}
Is the CLMonitor API still in a stabilization phase and not recommended for production release? I would appreciate guidance on the correct usage.
If these issues are expected to persist, I'm wondering if I should continue using the existing CLCircularRegion API instead.
Any insights or recommendations would be greatly appreciated.