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

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
384
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
4
622
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
360
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
771
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
409
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
515
Feb ’24
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
321
Feb ’24
LookAround « trademark »
I have a LookAroundPrewiew in a frame which itself is already small. On top of that is the LookAroundPreview automatically appended onto the preview. In fact it doesn’t really bother me per se, but it’s that my view doesn’t have much space. So is it possible customize the view by removing the text ? And the Apple Maps text at the bottom of the image which is fairly small isn’t a problem for me.
1
0
449
Feb ’24
Find Location Services in Sysdiagnose?
Hi guys! I am trying to extract Location Services data from an iPhone running developer mode, and have installed the "Location Services for iOS" Profile that can be found on the Profiles and Logs page. I have also read the Instructions PDF, and done the setup. I am having a hard time finding the actual logs after exporting the sysdiagnose folder. The folder is quite big and complex. Can someone please help me, and tell me where I can find it? Thanks!
1
1
552
Feb ’24
Setting Scene Size for MapKit JS
I would love to know if there is a way to manipulate how the scene size is set initially. I see that we have mapkit.MapSize(width, height) at our disposal but there isn't any clear documentation on its use case in the MapKit docs. I had to do some hacky workaround where I had to set the size like this. ` size = new mapkit.MapSize(1000, 600) map = new mapkit.Map("map"); map._impl._scene._size = size ` Is there a better way to handle this? On safari it is not setting correctly.
0
0
425
Feb ’24
multiple CLLocationManager instances running in parallel
although the Documentation implies that multiple CLLocationManager running in parallel should not intervene one another. I find some evidence that they do: for example a Medium posts title: "Single vs Multi CLLocationManager solutions" states: In multi instances of CLLocationManagers solution, there is the risk of collision where a feature / settings can impacts across instances of CLLocationManagers. another Medium post titled: "Measuring Differences of Degrees Using CLLocation’s CLHeading" states: however an important condition is that Apple recommends you initialize only ONE instance within your application at a time. This is because multiple instances running simultaneously has the effect of causing interference and distorting the data so is there some risk using CLLocationManager in parallel. is the configuration properties such as desiredAccuracy and distanceFilter can interrupt different CLLocationManagers running in parallel?
0
0
474
Mar ’24
CoreLocation's iBeacon monitoring stops reporting iBeacon when other BT device is connected in iOS Settings
Hello, We have an iOS application which detects when the user starts driving by detecting an USB iBeacon which is installed in the car of the users. For that we are monitoring the iBeacon region with CoreLocation and we are detecting the iBeacon when the locationManager(_:didDetermineState:for:) delegate method is called. We received some reports from a user that the iBeacon monitoring stops working when a specific BT device (specifically a hearing aid) is connected to the iPhone. The hearing aid is connected in the iOS Settings > Bluetooth page, similar how a regular BT headset is connected. When the hearing aid is disconnected then the iBeacon monitoring resumes and starts working properly again. We can't reproduce this issue with our BT headsets, so maybe the problem is specific to just some BT device connections? The advertising time interval of the iBeacon is 100mS as requested in the Apple documentation. Previously we had problems when a phone call was made through a BT headset when we used an advertising interval > 100mS in order to improve the battery usage of the iBeacon. But we changed to use an USB iBeacon, so the battery usage is not a concern anymore. Did somebody experience similar issues or has a solution? Specifically, can some specific BT connections set up in iOS Settings > Bluetooth page interfere with the iBeacon monitoring when using CoreLocation? Thank you very much!
1
0
483
Mar ’24
Is it possible to identify if offline map cache loaded or not
If I load a map while my device is online, I can access this map offline via the default caching mechanism. I need to be able to identify if a map cache is unavailable when my device is offline and react accordingly. For example, if I am offline and I load a map and the cache is unavailable i.e the map tiles are greyed out, I want to display a message to the user. The AppKit delegate had a method to identify when a map loaded but I do not see an equivilient way of doing this in Map. Any ideas?
0
0
414
Mar ’24
CoreLocation returns asynchronous data that may not be synchronized with Japan Post's data
Hi I want to inquire about the data returned from CoreLocation update and whether it is accurate. I am attempting to retrieve the local address in Japan based on the postal code, and I have observed differences in the returned data. When calling the information retrieval function with the postal code 3360042, the returned data is as follows: Locality: さいたま市 SubLocality: 南区 Corresponding to Japan Post: https://www.post.japanpost.jp/cgi-zip/zipcode.php?pref=11&city=1111080&id=38748 the displayed information on the website includes "Locality + SubLocality". When calling the information retrieval function with the postal code 1350064, the returned data is as follows: Locality: 江東区 SubLocality: 青海 Corresponding to Japan Post japan post: https://www.post.japanpost.jp/cgi-zip/zipcode.php?pref=11&city=1111080&id=38748 the displayed information on the website only includes "Locality" not includes SubLocality. Is it possible that CoreLocation has been updated? The current data seems to deviate from the design of our application. Please provide me with a solution to determine when to use "Locality + SubLocality" versus just "Locality" to obtain the local address. Thank.
0
0
405
Mar ’24
CoreWLAN returning null SSID with PyObjC on MacOS 14.4 with Location Services enabled
I have a Python script that returns a scan result with scanForNetworksWithName using CoreWLAN with PyObjC. It provides info on ssid and such like the airport command. When upgrading to MacOS 14.4 however SSID is now Null. I read this was due to changes in permissions and location services needed to be enabled. I have enabled access to location services and I am able to use CoreLocation to get a location however I still do now see the SSID. Here is my script, that does both location and scan: import CoreWLAN import CoreLocation from time import sleep import re wifi_interface = CoreWLAN.CWInterface.interface() networks, error = wifi_interface.scanForNetworksWithName_error_(None, None) location_manager = CoreLocation.CLLocationManager.alloc().init() location_manager.startUpdatingLocation() max_wait = 60 # Get the current authorization status for Python for i in range(1, max_wait): authorization_status = location_manager.authorizationStatus() if authorization_status == 3 or authorization_status == 4: print("Python has been authorized for location services") break if i == max_wait-1: exit("Unable to obtain authorization, exiting") sleep(1) coord = location_manager.location().coordinate() lat, lon = coord.latitude, coord.longitude print("Your location is %f, %f" % (lat, lon)) print(f"{'SSID' : >32} {'BSSID' : <17} RSSI CHANNEL HT CC SECURITY") for i in networks: print(f"{'SSID' : >32} {'BSSID' : <17} RSSI CHANNEL HT CC SECURITY") for i in networks: print(f"{i.ssid() or '' : >32} {i.bssid() or '' : <17} {i.rssiValue() : <4} {i.channel() : <6}") It worked fine in MacOS 13.6 but with MacOS 14.4 I have the null SSID issue. We went through something similar with MacOS 10.15 where BSSID became Null. At the time I couldn't find a workaround, but sometime around MacOS 13.x I was able to generate the request for location services. After granting the request I was able to see BSSID again. It seems like we have a similar bug to this again. Thread about the BSSID issue: https://github.com/ronaldoussoren/pyobjc/issues/484
4
2
1.1k
Mar ’24
Why didn't they use .task in the code sample?
If they had used .task they could have removed the class LocationsHandler: ObservableObject and simply done: struct ContentView: View { @State var lastLocation: CLLocation? var body: some View { VStack { ... } .task { let updates = CLLocationUpdate.liveUpdates() for try await update in updates { if let loc = update.location { self.lastLocation = loc } } } And saved themselves about 20 or so lines of code. .task was added in the year before so it isn't the case that it wasn't available to the CoreLocation team yet. To wrap async/await in a Combine's ObservableObject is very strange. They could have also used @AppStorage instead of UserDefaults and saved another few lines. To be honest this is some of the strangest SwiftUI code I've seen.
0
0
440
Mar ’24