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

The RSSI obtained from CLBeacon is always 0
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)]
0
0
235
Feb ’24
UIKit mapView color annotations
I have tried to make colored annotations in mapView (shown in the commented sections) but they always appear in black. Any help would be appreciated. func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "TempAnnotationView") annotationView.canShowCallout = true annotationView.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) let configuration = UIImage.SymbolConfiguration(pointSize: 10, weight: .thin, scale: .default) if annotation.title == "Start" { // let config = UIImage.SymbolConfiguration.preferringMulticolor() // let image = UIImage(systemName: "flag.fill", withConfiguration: config) // // palette // let config2 = UIImage.SymbolConfiguration(paletteColors: [.systemRed, .systemGreen, .systemBlue]) // let image2 = UIImage(systemName: "person.3.sequence.fill", withConfiguration: config2) // // hierarchical symbols // let config3 = UIImage.SymbolConfiguration(hierarchicalColor: .systemIndigo) // let image3 = UIImage(systemName: "square.stack.3d.down.right.fill", withConfiguration: config3) // // color // let image4 = UIImage(systemName: "cone.fill")?.withTintColor(.systemRed, renderingMode: .alwaysTemplate) // annotationView.image = image4 annotationView.image = UIImage(systemName: "poweron", withConfiguration: configuration) } return annotationView }
0
0
393
Feb ’24
Any control of MapKit font sizes?
I understand that MapKit automatically sizes the font based on the system Dynamic Type size. The thing is, the default font size is plenty legible for me system wide except for some type in MapKit, while other type in MapKit is already plenty big. For instance, the stream names are much harder to read than they should be by default. And if I increase the system Dynamic Type size, then it makes some MapKit text much larger than needed, while the stream text can still be hard to read. So is there anyway to override or adjust font sizes in MapKit? I'd like to be able to apply percentages to Dynamic Type suggestions. Like for streams, I'd like to scale it somewhere between 133% and 150%. The smallest Dynamic Type is size is .caption2 at 11 points with default settings. With default Dynamic Type settings, it looks like MapKit is drawing stream text around 7 points.
0
0
316
Feb ’24
visionOS: Moving window with a Map causes app to freeze
I'm developing a map-based app for visionOS. The loads map data from a server, using JSON. It works just fine, but I noticed the following effect: If I move the app's window around, it freezes; either on the first movement, or on one of the subsequent ones. The map cannot be panned anymore, and all other UI elements lose their interactivity as well. I noticed this issue before, when I was opening the map on app startup (and here it even happened without moving the window). Since I added a short delay, this was resolved. There was no log message in this case. However, when I noticed that it also happens if I move the window around, I saw that Xcode logs an error: +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior. trace=( 0 UIKitCore 0x0000000185824a24 __42+[UIView(Animation) setAnimationsEnabled:]_block_invoke + 112 1 libdispatch.dylib 0x0000000102a327e4 _dispatch_client_callout + 16 2 libdispatch.dylib 0x0000000102a34284 _dispatch_once_callout + 84 3 UIKitCore 0x0000000185824ad8 +[UIView(Animation) performWithoutAnimation:] + 56 4 SwiftUI 0x00000001c68cf1e0 OUTLINED_FUNCTION_136 + 10376 5 SwiftUI 0x00000001c782bebc OUTLINED_FUNCTION_12 + 22864 6 SwiftUI 0x00000001c78285e8 OUTLINED_FUNCTION_12 + 8316 7 SwiftUI 0x00000001c787c288 OUTLINED_FUNCTION_20 + 39264 8 SwiftUI 0x00000001c787c2cc OUTLINED_FUNCTION_20 + 39332 9 UIKitCore 0x000000018582fc24 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1496 10 QuartzCore 0x000000018a05cf00 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 440 11 QuartzCore 0x000000018a068ad0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 124 12 QuartzCore 0x0000000189f80498 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 460 13 QuartzCore 0x0000000189fb00b0 _ZN2CA11Transaction6commitEv + 652 14 VectorKit 0x00000001938ee620 _ZN2md12HoverSupport18updateHoverProxiesERKNSt3__16vectorINS1_10shared_ptrINS_5LabelEEEN3geo12StdAllocatorIS5_N3mdm9AllocatorEEEEE + 2468 15 VectorKit 0x0000000193afd1cc _ZN2md15StandardLabeler16layoutForDisplayERKNS_13LayoutContextE + 156 16 VectorKit 0x0000000193cf133c _ZN2md16CompositeLabeler16layoutForDisplayERKNS_13LayoutContextE + 52 17 VectorKit 0x0000000193abf318 _ZN2md12LabelManager6layoutERKNS_13LayoutContextEPKNS_20CartographicRendererERKNSt3__113unordered_setINS7_10shared_ptrINS_12LabelMapTileEEENS7_4hashISB_EENS7_8equal_toISB_EEN3geo12StdAllocatorISB_N3mdm9AllocatorEEEEERNS_8PassListE + 2904 18 VectorKit 0x0000000193cad464 _ZN2md9realistic16LabelRenderLayer6layoutERKNS_13LayoutContextE + 464 19 VectorKit 0x0000000193658b54 _ZNSt3__110__function6__funcIZN2md9realistic20RealisticRenderLayer5frameERNS2_13LayoutContextEE3$_0NS_9allocatorIS7_EEFvvEEclEv + 180 20 VectorKit 0x00000001936584cc ___ZN3geo9TaskQueue14queueAsyncTaskENSt3__110shared_ptrINS_4TaskEEEPU28objcproto17OS_dispatch_group8NSObject_block_invoke + 80 21 libdispatch.dylib 0x0000000102a30f98 _dispatch_call_block_and_release + 24 22 libdispatch.dylib 0x0000000102a327e4 _dispatch_client_callout + 16 23 libdispatch.dylib 0x0000000102a3aa80 _dispatch_lane_serial_drain + 916 24 libdispatch.dylib 0x0000000102a3b7c4 _dispatch_lane_invoke + 420 25 libdispatch.dylib 0x0000000102a3c794 _dispatch_workloop_invoke + 864 26 libdispatch.dylib 0x0000000102a481a0 _dispatch_root_queue_drain_deferred_wlh + 324 27 libdispatch.dylib 0x0000000102a475fc _dispatch_workloop_worker_thread + 488 28 libsystem_pthread.dylib 0x0000000103b0f924 _pthread_wqthread + 284 29 libsystem_pthread.dylib 0x0000000103b0e6e4 start_wqthread + 8 I disabled all my withAnimation() statements, and the problem persists. I also thought it might be related to my own network fetches, but I think all apply their changes on the main thread. And when I turn on network logging for my own fetching logic, I do not see any data coming in. I also do not think there should be a reason for it. How can I debug such a situation, so I know, which call actually threw this message? I'd like to know if it is my code or a bug in the SwiftUI map itself.
3
0
635
Feb ’24
geolocation represented on 3d model
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
0
0
260
Feb ’24
CLMonitor is Not Working and No way to debug!
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
0
2
430
Feb ’24
Cannot select my created MKMapItem on the Map
Hi, I am learning about MapKit for SwiftUI, at first I created the MKMapItem @State private var mapSelection: MKMapItem? @State var starbucksReserve = MKMapItem(placemark: .init(coordinate: CLLocationCoordinate2D(latitude: 41.894178596474575, longitude: -87.62451598445733)))` I put that in the Map Map(position: $cameraPosition,selection: $mapSelection){ Marker("Starbucks Reserve", systemImage: "cup.and.saucer.fill" ,coordinate: starbucksReserve.placemark.coordinate) } Even though I have put the selection $mapSelection, my Marker is not selectable. I am not sure why. I tried to fix it by changing mapSelection to Int? and made a tag for Marker, but because I am learning how to use it so I want to make sure why marker cannot be selectable with the first approach? Thank you
0
0
292
Feb ’24
How to handle thousands of map annotations (+100K) in a MKMapView?
According to the MKMapview, all annotations should be added to the map: https://developer.apple.com/documentation/mapkit/mkmapview When configuring your map interface, be sure to add all of your annotation objects right away. The map view uses the coordinate data in each annotation object to determine when the corresponding annotation view needs to appear onscreen. When an annotation moves onscreen, the map view asks its delegate to create a corresponding annotation view. If your app has different types of annotations, it can define different annotation view classes to represent each type. But this has a very low performance when the map is zoomed out and all annotations are visible (although market already filters out most of the annotations and only displays a few). As fas as I've seen, the suggestion from the documentation doesn't scale properly when the number of annotations is very large. Grouping doesn't help, neither using reusable annotations. Is the only option here, handling manually the add/remove annotations as the map rect changes?
2
0
919
May ’23
CLLocationManagerDelegate Bug on VIsionOS
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.
0
0
266
Feb ’24
how to get user live location in Background and terminated mode?
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() } } }
0
0
351
Jan ’24
MapKit top MKTileOverlay blendMode overrides lower MKTileOverlay blendMode
I need multiple MKTileOverlays with multiple blendModes. Apparently using an overlay with a different blend causes the layer under to use the same blend mode. For the example below, using a normal blend mode on top of a soft light blend mode causes a normal blend mode to be used instead of soft light. The soft light layer is rendered as expected until the normal layer is displayed starting at zoom level 15. First, I've subclassed MKTileOverlay to add an overlay type so that the correct renderer is provided per overlay. (I know there is a title, but I prefer this) enum OverlayType { case softLight, normal } class TileOverlay: MKTileOverlay { var type: OverlayType = .normal } Then setup layers and renderers in the typical fashion: var softLightRenderer: MKTileOverlayRenderer! var normalRenderer: MKTileOverlayRenderer! private func setupSoftlightRenderer() { let overlay = TileOverlay(urlTemplate: "http://localhost/softlight/{z}/{x}/{y}") overlay.type = .softLight overlay.canReplaceMapContent = false overlay.minimumZ = 9 overlay.maximumZ = 20 mapView.addOverlay(overlay, level: .aboveLabels) softLightRenderer = MKTileOverlayRenderer(tileOverlay: overlay) tileRenderer.blendMode = .softLight } private func setupNormalRenderer() { let overlay = TileOverlay(urlTemplate: "http://localhost/normal/{z}/{x}/{y}") overlay.type = .normal overlay.canReplaceMapContent = false overlay.minimumZ = 15 overlay.maximumZ = 20 mapView.addOverlay(overlay, level: .aboveLabels) normalRenderer = MKTileOverlayRenderer(tileOverlay: overlay) normalRenderer.blendMode = .normal } func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { if let overlay = overlay as? TileOverlay { switch overlay.type { case .softLight: return softLightRenderer case .normal: return normalRenderer } } print("Warning: using unhandled overlay renderer") return blankRenderer } override func viewDidLoad() { ... setupSoftlightRenderer() setupNormalRenderer() } Interestingly, if I put the overlays at two different levels, one .aboveLabels and another .aboveRoads it works as expected. The problem is that limits me to two different overlay blend modes. I really could use more than two. I tried every possible variation of inserting the layers at different indexes and methods, but the only two that seem to work are the .aboveLabels and .aboveRoads. How can I use more than two different blend modes?
1
0
372
Jan ’24
RealityKit : Why ARGeoTrackingConfiguration is not available everywhere ?
Hi, The ARkit is a great tool, I have my small app doing things, and it's fun! but I wanted to try to migrate from ARWorldConfiguration to ARGeoTrackingConfiguration - https://developer.apple.com/documentation/arkit/argeotrackingconfiguration and then we can see that this configuration is limited to a couples of USA only cites. But I can't manage to figure Why and if, in the near future, this will be expanded world wide ?
2
0
1.3k
Jan ’21
Join in Apple Developer and Find My Network as a Chinese College Student
Hi, I'm a college student in Hangzhou, China. I want to learn and develop with Find My Network and other useful Apple's tech. But when I access the application website, I can't find the university entrance but only with company. Can I develop as a college student? Where can I be? Or in the same page, what's the DUNS numbers? If only corps can, what's the fee to get the DUNS numbers with Apple's support? What's the fee to join in Apple Developments? Should I offer some documents such as Bank Corporate Account Statement? If I create a new corp to join in the development, what should I or corp need and do? I just wanna develop a school ID card with UWB tech and Apple's useful Find My Network. Hope to get your's help. Have a good day. Thanks!
0
0
341
Jan ’24
MapView mapType `.standard` iOS17 does not allow 3d
I am working on a virtual simulator for iOS 17 from my macbook. I want to have the initial view present the Map but zoomed out enough so that it's basically showing the whole world - in a 3d render. My understanding is that as of iOS17 if you have .standard for the MKMapView type, it should still render as 3D if the altitude is high enough. But on my simulator, I literally cannot zoom out any further. Is the right protocol to update the mapType to be .hybridFlyover? That seems different than the .standard (which I think is what I actually want). Does anyone have any idea / is there anything sticking out in this code? Here is my code: struct GlobeView: UIViewRepresentable { var coordinates: [IdentifiableCoordinate] func makeUIView(context: Context) -> MKMapView { let mapView = MKMapView() mapView.mapType = .hybridFlyover mapView.delegate = context.coordinator let camera = MKMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 0, longitude: 0), fromDistance: 1_000_000_000, pitch: 0, heading: 0) mapView.setCamera(camera, animated: true) return mapView } func updateUIView(_ uiView: MKMapView, context: Context) { let annotations = coordinates.map { coordinate -> MKPointAnnotation in let annotation = MKPointAnnotation() annotation.coordinate = coordinate.coordinate return annotation } uiView.addAnnotations(annotations) } class Coordinator: NSObject, MKMapViewDelegate { var parent: GlobeView init(_ parent: GlobeView) { self.parent = parent } } func makeCoordinator() -> Coordinator { Coordinator(self) } }
1
0
351
Jan ’24
Does CLMonitor work in simulator?
When I run CLMonitor in the simulator, event state remains at default. Although when running the same project on device, state does correctly change between satisfied and unsatisfied. In the simulator I did allow location updates when in use as I did on device. This occurs with the Apple sample code, Monitoring location changes with Core Location associated with the WWDC 2023 session Meet Core Location Monitor. Am I misusing simulator and/or CLMonitor?
1
0
392
Oct ’23