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

Ellipsoidal Altitude is always zero
I am trying to retrieve the ellipsoidal altitude from a CLLocation but it seems like an invalid value is always returned, no matter the vertical accuracy (which according to the documentation should just be > 0) I first encountered this problem while developing a tool to retrieve workouts from healthkit, but i tried this code in a playground and i still get zero. import CoreLocation var location = CLLocation(coordinate: CLLocationCoordinate2D(latitude: 46.071067, longitude: 13.234579), altitude: 113, horizontalAccuracy: CLLocationAccuracy(floatLiteral: 1.0), verticalAccuracy: CLLocationAccuracy(floatLiteral: 1.0), timestamp: Date()) print(location.ellipsoidalAltitude) Am I doing something wrong or is this a bug?
2
0
261
Sep ’24
requestWhenInUseAuthorization Crash iOS 18 Beta 4
When I call requestWhenInUseAuthorization in state kCLAuthorizationStatusNotDetermined on iOS 18 Beta 4 in the simulator, all my apps just terminate without any error message in the Xcode console (black screen with an activity indicator for a second or two and then it goes back to the springboard). I do have the NSLocationWhenInUseUsageDescription set in my Info.plist file. When running the exact same apps in Xcode 16.0 beta 4 (16A5211f) but with a iOS 17 simulator attached, it is working as expected by showing the location authorization dialog. Is this a known issue or am I missing something?
4
1
665
Jul ’24
App Clips Advanced Experiences not showing up in Apple Maps and Siri Suggestions
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?
6
1
500
Sep ’24
Image using MKLookAroundSnapshotter with Updated Scene
I'm trying to create a UIImage from a MKLookAroundScene, after the user has moved the scene, by looking (and moving) around. Is this possible? When I use MKLookAroundSnapshotter with the modified scene, I always get an image of the original (starting) scene. STEPS TO REPRODUCE Create a scene using MKLookAroundSceneRequest with coordinates. Use LookAroundPreview with a binding to MKLookAroundScene to get changes to the scene (based on looking around). User begins LookAround, moving the scene location and view. User ends LookAround The preview displays the updated scene properly. The scene's cameraFrameOverride values reflect the pitch, roll, yaw, and location changes. Pass the updated scene to MKLookAroundSnapshotter to get an image. Display the Image. The Image is the original scene (not what is displayed in the preview).
1
0
274
Sep ’24
Apple MapKit Js Token update
I might be being really ******, but I'm struggling to find a way to update the map kit token when it expires. We have a display that shows a map for a long time and for some reason the map stops loading and I think it's cause the token expires however I can't work out away to tell it to load a new token.
1
0
318
Aug ’24
Using CPVoiceControlTemplate in my CarPlay app to capture voice
I have a CarPlay navigation app and I would like to allow the user to speak an address and have our app search at that location. In the Waze app, it provides a button to tap, then it brings up a CPVoiceControlTemplate and you can give it directions or a location and it will then show you search results including the text you spoke as the title. I assume that app would have the same limitations as I do, so I am wondering how another app might do this? It was suggested that I use an App Intent with suggested phrases and then a Shortcut could perform the action. Is there documentation on this somewhere or am I going in the wrong direction here? Obviously Waze is doing what I am wanting so there must be a way. Can anyone point me in the right direction?
2
1
402
Sep ’24
What is the reason for the CLLocationmanager.locationServicesEnabled() "invoked on main thread" warning?
I am looking into a piece of old code where the mentioned method is called. + (bool)isLocationServicesEnabled { return [CLLocationManager locationServicesEnabled]; } I'm getting the classic "This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization: callback and checking authorizationStatus first." I have 2 questions: What is that error about, really? The locationServicesEnabled() has nothing to do with authorisation, it's just about the "location services" settings global on-off switch? (the authorisation check is .authorizationStatus) I don't understand why that call is such a big issue? It's just a setting? Why would that be so costly? Thankful for pointers! Have a good one
5
0
500
Sep ’24
Add the capability of "Access Wi-Fi information" and show the location access indicator
We met a question recently in our project, we try to achieve the SSID,so we need to do the following two things : request location permission add the capability of "Access Wi-Fi information" then the app always shows the location access indicator. , In the app privacy report , we see the app always request the location. But when I try to remove "Access Wi-Fi information" the capability , the scenario disappear. Any ideas can explain this ? How can I remove the location access indicator with out remove the "Access Wi-Fi information" . I indeed need this. Thanks in advance.
1
0
288
Sep ’24
How can I get something similar to launchOptions[UIApplication.LaunchOptionsKey.location] in SceneDelegate for iOS 13+ apps
I'm making an app for iOS 13+ devices. My project has both app delegate and scene delegate files. I'm using core location for significant location changes. I was able to detect significant location changes and system waking up my app in simulator using SignificantlyChanged app’s scheme. But when the launch options dictionary has 0 elements and the value for the key UIApplication.LaunchOptionsKey.location is always nil. Here is my AppDelegate.swift where the system will launch the app in background state when a significant location change is detected and execute the location fetch code. And location manager class. I want to know if the app is launched my the system or if it is launched by the user so I want to check if UIApplication.LaunchOptionsKey.location key has a value. But it is always nil and there is no alternative to it in SceneDelegate. When and how can I find a solution to this long due issue. import CoreLocation @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. if launchOptions != nil{ if launchOptions![UIApplication.LaunchOptionsKey.location] != nil{ print("Called from background location fetch") } } LocationService.shared.askForPermission() LocationService.shared.delegate = self return true } // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } } extension AppDelegate: LocationMangerDelegate{ func didFetchLocation(coordinate: CLLocationCoordinate2D) { print(coordinate) } func didFailToFetchLocation(error: Error?, message: String) { print(message) } }``` import Foundation import CoreLocation protocol LocationMangerDelegate: AnyObject{ func didFetchLocation(coordinate: CLLocationCoordinate2D) func didFailToFetchLocation(error: Error?,message: String) } class LocationService: NSObject{ private override init() { } weak var delegate: LocationMangerDelegate? static var shared = LocationService() lazy var locationManager: CLLocationManager = { var manager = CLLocationManager() manager.desiredAccuracy = kCLLocationAccuracyBest manager.allowsBackgroundLocationUpdates = true manager.pausesLocationUpdatesAutomatically = false manager.delegate = self return manager }() func askForPermission(){ print("INSIDE") locationManager.requestWhenInUseAuthorization() } func startLocationUpdates(){ self.locationManager.startUpdatingLocation() } func stopLocationUpdates(){ self.locationManager.stopUpdatingLocation() } } extension LocationService: CLLocationManagerDelegate{ func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) { let status = manager.authorizationStatus switch status { case .notDetermined: self.askForPermission() case .restricted: self.delegate?.didFailToFetchLocation(error: nil, message: "Location permission is restricted by the user") case .denied: self.delegate?.didFailToFetchLocation(error: nil, message: "Location permission is denied by the user") case .authorizedWhenInUse: self.locationManager.requestAlwaysAuthorization() case .authorizedAlways: self.locationManager.startMonitoringSignificantLocationChanges() @unknown default: break } } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { if let location = locations.first{ print(location) self.delegate?.didFetchLocation(coordinate: location.coordinate) self.stopLocationUpdates() } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print(error) self.delegate?.didFailToFetchLocation(error: error, message: error.localizedDescription) } }
1
0
379
Aug ’24
MapKit JS API not loading
I own a website (timeguessr.com) that uses the apple mapkit js api. I have had a number of reports in the last few weeks of users having the map not loading. Since I have not been able to recreate the problem I have asked people to send screenshots of what is logged to their developer tools console. In each case a ERR_HTTP2_PROTOCOL_ERROR 200 (OK) error is being logged when the user is trying to fetch from cdn.apple-mapkit.com endpoints. What is strange is this happens halfway through their games when they have already successfully loaded the map in previous rounds. Can anyone help? Thanks
1
0
502
Aug ’24
Did WeatherKit minutely precipitation intentionally change units?
I've noticed in the past few weeks that the minutely precipitation values reported by WeatherKit are much bigger than they were before. Specifically I'm referring to WeatherKit.MinuteWeather.precipitationIntensity. In my app, I convert to mm per hour: let mmPerHour = $0.precipitationIntensity.converted(to: UnitSpeed.kilometersPerHour).value * 1e6 This has worked perfectly since WeatherKit came out, but now when I look at rainy locations and compare with the built-in Apple Weather app on my phone, it seems that the new values are about 3x what they should be. I have checked this in multiple locations across the USA. My intuition says this is an inches/cm conversion issue (2.54x). Is this an intentional change in WeatherKit that requires me to update my app, or is this a bug on Apple's end??
2
0
343
Aug ’24
hello, where can I find the supporting file "info.plist" in xcode?
I always get the user location not found error even though I have activated my location import SwiftUI import MapKit import CoreLocation class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { private let locationManager = CLLocationManager() @Published var location: CLLocation? = nil @Published var authorizationStatus: CLAuthorizationStatus? = nil override init() { super.init() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { guard let newLocation = locations.last else { return } location = newLocation print("Updated location: \(newLocation.coordinate.latitude), \(newLocation.coordinate.longitude)") } func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { authorizationStatus = status if status == .authorizedWhenInUse || status == .authorizedAlways { locationManager.startUpdatingLocation() } } } private func sectionTitle(_ title: String) -> some View { Text(title) .font(.headline) .fontWeight(.bold) .padding(.bottom, 8) } private func openAppleMaps() { let destinationLatitude: CLLocationDegrees = -6.914744 let destinationLongitude: CLLocationDegrees = 107.609810 guard let currentLocation = locationManager.location?.coordinate else { print("Lokasi pengguna tidak ditemukan.") return } let currentLatitude = currentLocation.latitude let currentLongitude = currentLocation.longitude // URL encode parameters let urlString = "http://maps.apple.com/?saddr=\(currentLatitude),\(currentLongitude)&daddr=\(destinationLatitude),\(destinationLongitude)&dirflg=d" guard let appleMapsUrl = URL(string: urlString) else { print("URL tidak valid.") return } // Open Apple Maps UIApplication.shared.open(appleMapsUrl, options: [:]) { success in if !success { print("Gagal membuka Apple Maps.") } } }
1
0
347
Aug ’24
Are several Proximity and Beacon related libraries methods and properties deprectaed and now unusable in iOS 18 beta?
Hi, Please let me know iOS 18 beta have deprecated/ stopped support for which of the following: proximityUUID CLBeaconRegion (instancetype)initWithProximityUUID:(NSUUID *)proximityUUID identifier:(NSString *)identifier (void)startRangingBeaconsInRegion:(CLBeaconRegion *)region -startRangingBeaconsSatisfyingConstraint: , is this also deprecated in iOS 18 beta, since: CLBeaconIdentityConstraint is deprecated right? CLBeaconIdentityCondition is not supported in XCode 15.3. What should I do for this? Should I install XCode 16 beta? locationManager:didRangeBeacons:satisfyingConstraint: can we use it in iOS 18 beta, since, CLBeaconIdentityConstraint is deprecated? what is alternative startMonitoring(for:) is also deprecated in iOS 18 beta right? Also, can someone specify or create a documentation on how beaconing shall be monitored, ranged and locationManager delegate methods pertaining to beaconing to be used in iOS 18 beta?
10
1
786
Jun ’24
Loading large amounts of coordinates and annotations to a map?
My query might return 20,000 coordinates. Does MapKit JS try to load all the coordinates at once into the map or does it only load what’s in the viewport of the map if we were to load 20,000 annotations into the say something like “landmark data” const? We have 900,000 coordinates to load into Los Angeles and are planning how we will do this. Obviously we can’t load 900,000 coordinates at once without performance issues, but some query’s return 20,000 results. Can someone point me to some information about large datasets and MapKit js or let me know if it’s handled and already built in to not try to load that many locations at once?
0
0
326
Aug ’24