Hello there,is it possible to let users take Maps Web Snapshots after searched a location on mapkit js?
Maps & Location
RSS for tagLearn how to integrate MapKit and Core Location to unlock the power of location-based features in your app.
Post
Replies
Boosts
Views
Activity
I'm seeing a strange situation where my MapKit JS page is stuck in dark mode. I'm trying to implement a custom version of the sample code "Callout Accessory Views" from here: https://maps.developer.apple.com/sample-code/accessory-views/
I have 2 simple examples of my implementation of this. I like the simple look of the annotation. I can customize the left and right accessory. Here are 2 samples of my map:
https://zrl.me/debug1.html
https://zrl.me/debug2.html
I really want something that looks like debug1.html, but it is ALWAYS shown in dark mode. When I inspect the element where the annotation says "Washington, DC", there is a CSS class ".mk-dark-mode".
My Mac does not use Dark mode, or Auto, but somehow this page always shows Dark. It happens at night and during the day. Researching this further, I saw that there area a couple ways of fixing this. In MapKit JS, you should be able to assign:
colorScheme: mapkit.Map.ColorSchemes.Light
In the Map constructor. This does not force the map into Light mode for me..
More research shows that this should force the entire page into light mode, but it does not work here:
<meta name="color-scheme" content="light only">
The difference between debug1.html and debug2.html is that debug1.html sets:
accessoryViewLeft.className = "left-accessory-view";
When this class is set, since the callout is actually a bit like a speech bubble, it creates a SVG shape behind the annotation. It looks like when either the left or right sides of the callout have a background-color applied, MapKit JS tries to smartly adjust the coloration of the bubble, and forces the right-side to have a WHITE background, instead of a contrasting dark background.
I have a few simple questions, any one of these could help resolve this issue?
Does anyone know why my instance of this is being forced into dark mode? This does not happen in the sample code.
Does anyone know how to force the map into light mode?
Is there a way to stylize the main section of the annotation callout?
Is there a way to change/force the stylizing of the speech bubble to have something other than a white background-color on the second half of the gradient on the SVG?
I am having some problem with accessing the CLLLocationManager location from my widget. It works fine with Xcode 15 running on a iOS17 simulator. But running it on a iOS17 device gives me an error in the delegate:
To access the location manager, I have this class:
class WidgetLocationManager: NSObject, CLLocationManagerDelegate {
var locationManager: CLLocationManager?
private var handler: ((CLLocation?) -> Void)?
override init() {
super.init()
DispatchQueue.main.async {
print("WidgetLocationManager: init")
self.locationManager = CLLocationManager()
if self.locationManager!.authorizationStatus == .notDetermined {
print("WidgetLocationManager: init - auth status is Undetermined")
} else {
print("WidgetLocationManager: init - auth status = \(self.locationManager!.authorizationStatus)")
}
}
}
func fetchLocation(handler: @escaping (CLLocation?) -> Void) {
self.handler = handler
self.locationManager = CLLocationManager()
self.locationManager!.delegate = self
self.locationManager!.requestLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let lastLocation = locations.last {
if (CLLocationCoordinate2DIsValid(lastLocation.coordinate) == true && abs(lastLocation.timestamp.timeIntervalSinceNow) < 60 && lastLocation.horizontalAccuracy < 200.0 && lastLocation.horizontalAccuracy > 0.0) {
self.handler!(locations.last!)
}
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("WidgetLocationManager: locationManager didFailWithError = \(error)")
self.handler!(nil)
}
}
When run on device, I get an error:
WidgetLocationManager: locationManager didFailWithError = Error Domain=kCLErrorDomain Code=1 "(null)"
Code = 1 in CLError is kCLErrorDenied ("Access to location or ranging has been denied by the user")
This is despite getting the following output in the init method:
WidgetLocationManager: init - auth status = CLAuthorizationStatus(rawValue: 4)
The weird thing is that it works fine in the simulator. On device, I've tried deleting and reinstalling the app a couple of times, restarting the device, making sure the privacy setting is correct etc.
Also, on the iOS17 device, when I am in the "Add Widget" page, the location manager runs fine in the preview screen, and shows the 'current location' to the user. But as soon as I add the widget to the home screen, it starts giving me this problem where the location can't be found, and I have to display an error message in the widget.
I have the following keys in the Info.plist for the widget:
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription
NSWidgetWantsLocation
The app target also has the following keys in the Info.plist:
NSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
Any idea for what I can try to fix this problem?
Thanks.
I built an autopilot for my boat, and took it further by writing an IOS app to control it via bluetooth with my phone. Everything was working great, until I thought I'd add the ability to navigate a route. Here's what has me stumped...
I've got location manager generating updates, as long as the phone is moving (ever so slightly) in my hand. I've got the display setup to never sleep, and the phone is plugged in to power. If I put the phone down, I get a few new locations, then the location freezes. The didUpdateLocations delegate is called, but the location never changes.
I've tried a number of settings but no matter what I try, none have solved the still phone issue. My current design uses
self.locationManager?.requestLocation()
sent on at programmable interval, so that I get updates with reasonable spacing. The updates come, but the location is identical if the phone is still (laying on the dash of the boat). If I just "wiggle" the phone a bit, locations come with a new value. If I keep "wiggling the phone, I get new locations every call to requestLocation.
Seems like there is some kind of inactivity timer associated with didUpdataLocations that prevents retrieving new locations. It just re-sends the previous location.
This issue has nothing to do with using requestLocation, since I had the same issue when didUpdateLocations was running on its own timing. I added the code and logic to support requestLocation in an attempt to force a new location.
Has anyone experienced this or have any idea how to force a "new" location when the phone is still?
I'm using Xcode Version 14.3.1 (14E300c)
The phone is an iPhone 12
and the deployment target is set to 15.3
Here's how I currently configure location manager...
This is one of a number of attempts, but all have the same issue.
if locationManager == nil{
print("****** instantiating locationManager ******")
locationManager = CLLocationManager()
locationManager!.distanceFilter = kCLDistanceFilterNone
// locationManager!.distanceFilter = 3
locationManager!.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager!.delegate = self
locationManager!.showsBackgroundLocationIndicator = true
locationManager!.startUpdatingLocation()
locationManager!.startUpdatingHeading()
locationManager!.allowsBackgroundLocationUpdates = true
}
}
I would like to retrieve the user's current location when they are logging some information with my App Intent. When the app has been just run, this works just fine, but if it has been force quit or not run recently, the Core Location lookup times out. I have tried logging the information and using the Core Location background mode, and I can verify that the background mode is triggering because there is an indicator on the status bar, but the background mode does not seem to fire the delegate.
Is there a good way to debug this? When I run the app, everything works just fine, but I can't confirm that delegate calls are going through because I can't debug from an App Intent launch.
Here is the perform method from my App Intent
func perform() async throws -> some ProvidesDialog {
switch PersistenceController.shared.addItem(name: name, inBackground: true) {
case .success(_):
return .result(dialog: "Created new pin called \(name)")
case .failure(let error):
return .result(dialog: "There was a problem: \(error.localizedDescription)")
}
}
addItem calls LocationManager.shared.getCurrentCoordinates:
func getCurrentCoordinates(inBackground: Bool = false, callback: @escaping (CLLocation?) -> Void) {
if lastSeenLocation != nil {
callback(lastSeenLocation)
return
}
if inBackground {
locationManager.allowsBackgroundLocationUpdates = true
locationManager.showsBackgroundLocationIndicator = false
}
let status = CLLocationManager.authorizationStatus()
guard status == .authorizedAlways || status == .authorizedWhenInUse else {
DispatchQueue.main.async { [weak self] in
self?.callback?(nil)
self?.locationManager.allowsBackgroundLocationUpdates = false
}
return
}
self.callback = callback
locationManager.startUpdatingLocation()
}
The CLLocationManager delegate didUpdateLocations then calls the callback with the location and sets allowsBackgroundLocationUpdates to false. And the callback saves the location data to Core Data.
What is the best practice for using Core Location in an App Intent?
I am able to see this issue even in https://developer.apple.com/maps/web/
When I zoom out, some tiles are not rendering.
I am using latest chrome version
I have had some trouble with that "didRangeBeacons" was called with beacons that were not present. They were preset some minutes before. And these calls never seemed to stop coming. iOS must be storing the beacons somehow.
My first idea was to update the deprecated "locationManager:didRangeBeacons:inRegion" to "locationManager:didRangeBeacons:satisfyingConstraint". But the type "CLBeaconIdentityConstraint" is also deprecated, use " CLBeaconIdentityCondition" instead. How can the type be deprecated, but not the function using it?
I see no API functions for this new "CLBeaconIdentityCondition" type, e.g. something like "start/stopRangingBeaconsSatisfyingCondition" or "locationManager:didRangeBeacons:satisfyingCondition:".
In iOS 17 Beta (beta1 to RC versions all have this issue), my phone gets extremely hot when I open any app that continuously accesses GPS. The built-in Maps app heats up relatively well, but other third-party apps heat up quickly, causing the device to throttle, reduce brightness, and even lag.
Device:iPhone 12
Is there any plan in the future to add bike as type of conveyance in MKDirectionsTransportType (as available in the Maps app)?
@Gualtier Malde, My app has not been able to send location updates in the background past 5hrs even after implementing all the changes you specified
The debugger spits out nothing ....
allowsBackgroundLocationUpdates must be set to TRUE
distanceFilter must not be set
desiredAccuracy must be kCLLocationAccuracyHundredMeters or better. If you’re using numeric values, it must be set to less than 1000 meters (We set it to 100m)
We have been losing hundreds of enterprise clients as a result of this, is there something we can do to ensure the behaviour is similar or same to iOS <16.4?
Am looking to finally updating some old code now that we are dropping iOS 15 support and want to move to the new mkMapView configurations such as MKHybridMapConfiguration.
However when I use that configuration I cannot get it to show traffic conditions, even though I am setting showsTraffic = true
Bug, feature, dumb coding error on my part?
I am switchingt to the new WWDC 2023 SwiftUI map with user location and a few map annotations.
I find if I use .mapStyle(.imagery(elevation: .flat)) as the map style, the map will be loaded with a reasonably zoomed area.
However, if I use .mapStyle(.imagery(elevation: .realistic)) on the same map, the simulator will give me a view of the entire planet. I have to manually zoom in everytime to find the user location and annotations, which is not very convenient. This is the only map style configuration that does this.
I am not very sure if this is a feature or a inconsistency bug. If this is a feature, I cannot see the purpose of it.
Hey yall--seemingly once in a blue moon whenever fetchLocation gets called in here from a widget that is requesting location, it calls on the manager's requestLocation, the widget will crash. Crash stack backtrace shows this:
And this is the affected code:
import Foundation
import CoreLocation
class WidgetLocationFetcher: NSObject, CLLocationManagerDelegate {
let manager = CLLocationManager()
private var handler: ((CLLocation?) -> Void)?
override init() {
super.init()
DispatchQueue.main.async {
self.manager.delegate = self
self.manager.requestWhenInUseAuthorization()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.handler?(locations.last!)
self.handler = nil
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
self.handler?(nil)
self.handler = nil
}
func fetchLocation(handler: @escaping (CLLocation?) -> Void) {
self.handler = handler
self.manager.requestLocation()
}
}
I am not too sure what could even be causing this, although I am running watchOS 10 beta 8 and iPadOS 17 beta 8 on the devices experiencing this crash. Has anyone ever solved this issue?
MacBook cannot detect my location. Google Maps, HorizonBlue, and others tell me to enable location services. Everything seems to be enabled but the problem persists. Started around a month ago.
TRIED: Resetting the MacBook, Shut down, Restart, Clear cookies
VERSION: Sonoma Beta 14.0 (23A5301h)
Hello all,
I want to ask is CLGeocoder free or we needs pay more if reach the limit 25,000 calls daily?
if needs to pay, is there any information about the pricing list?
Thank you,.. Have a nice day.
Hi everyone,
I just implemented MapKitJS into my Ionic Vue app. At the same time I noticed a disproportionate amount of service calls (see image) without implementing dedicated calls to the Apple Maps Server API for example for autocompletion.
Therefore the question arrised: Are those service calls mentioned in the MapKitJS Dashboard something differenent to the Apple Maps Server API, due to both disclaimed with 25k service calls free per month. Added to that, what causes those services calls in the MapKitJS implementation and how can it be made more efficent to make optimal use of the Apple Maps Server API calls?
Thanks for clarifing and helping out.
Hello all!
Apple presented the all-new Core Location Monitor at WWDC 2023.
It changes the logic of monitoring for iBeacons with a new approach of adding CLCondition-s for monitoring iBeacon values like UUID, major, and minor.
This, I suppose (please do feel free to correct me) is meant to replace current (now deprecated) startMonitoring implementation.
Now, we it's a fact that it is impossible to monitor more than 20 regions at once.
Question: does the new CLMonitor let us bypass this limit? If not, what's the maximum number of CLConditions we can add to a CLMonitor?
We are currently experiencing a very interesting issue when accessing the location in the background with CLLocationManager.
The user has given our app the "whenInUse" permission for locations and in most cases the app provides location updates even when it's in the background.
However, when we started to use other navigation apps in the foreground we saw that the func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) method was called with (kCLErrorDomain error 1.).
The user hasn't changed the location permission and we saw that locations were delivered once the user opened the app again.
I don't see anything in the documentation explaining this issue, but I chatted with other developers that confirm that specific behavior.
Am I missing something here?
I'm looking to integrate Apple Maps features into my WordPress website for location-based content. Has anyone successfully accomplished this and can share insights on how to seamlessly incorporate interactive maps within the WordPress platform? Any recommended plugins, APIs, or coding approaches that ensure a smooth integration and optimal user experience across devices? I'd greatly appreciate any guidance on best practices, potential challenges to watch out for, and practical tips based on your experiences. Thank you!
When using the MapKit JS map on with satellite map type, the map is initially loaded properly. All the tiles are downloaded successfully (can confirm this from the Network tab) and these tiles are rendered on the map at first. However, then one or more of these tiles disappear from the map, leaving an empty space on the map and the grid background is seen on the tile(s). When the map is dragged even one pixel, the tile(s) reappear (even when no new tiles are downloaded, they are retrieved from memory). This error occurs only on the satellite map and it occurs consistently in my project and in my demo, with my own token or by using a public token (as seen in the demo below). Did anyone come up with this issue and if they did, how did they solve it?
Here is the sample output:
Demo Code :
<head>
<script src="https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js"></script>
<style>
#map {
width: 1000px;
height: 600px;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
function getToken() {
return $.get("https://jkap-mapkitjs-demo.glitch.me/token").then(function (
data
) {
return {
token: data
};
});
}
getToken().then(function (data) {
mapkit.init({
authorizationCallback: function (done) {
done(data.token);
}
});
var map = new mapkit.Map("map", {
mapType: "satellite",
});
});
</script>
</body>