Post not yet marked as solved
I added multiple MKPolyline to a MKMapView. It looks fine on the beginning, but when I start zooming, the border of the MKPolyline gets lost on some poly lines.
zoomed out:
zoomed in:
here is the code I used:
import MapKit
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
mapView.mapType = .mutedStandard
mapView.pointOfInterestFilter = .excludingAll
let tiles = [
MapTile(x: 8586, y: 5514),
MapTile(x: 8587, y: 5514),
MapTile(x: 8588, y: 5514),
MapTile(x: 8587, y: 5515),
]
let polygons = tiles.map { tile in
MKPolygon(coordinates: tile.locations, count: tile.locations.count)
}
mapView.addOverlays(polygons, level: .aboveLabels)
}
}
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if let mapTile = overlay as? MKPolygon {
let renderer = MKPolygonRenderer(polygon: mapTile)
renderer.fillColor = .systemBlue.withAlphaComponent(0.15)
renderer.strokeColor = .systemBlue
renderer.lineWidth = 0.7
return renderer
}
return MKOverlayRenderer(overlay: overlay)
}
}
struct MapTile: Identifiable, Hashable {
let x: Int
let y: Int
var id: String { "\(x)-\(y)" }
static let zoomFactor = Double(1 << 14)
static func locationOrigin(tileX: Int, tileY: Int) -> CLLocationCoordinate2D {
let lon = (Double(tileX) / MapTile.zoomFactor) * 360.0 - 180.0
let lat = atan( sinh (.pi - (Double(tileY) / MapTile.zoomFactor) * 2 * Double.pi)) * (180.0 / .pi)
return CLLocationCoordinate2D(latitude: lat, longitude: lon)
}
var locationOrigin: CLLocationCoordinate2D {
MapTile.locationOrigin(tileX: x, tileY: y)
}
var locations: [CLLocationCoordinate2D] {
let topLeft = locationOrigin
let topRight = MapTile.locationOrigin(tileX: x + 1, tileY: y)
let bottomRight = MapTile.locationOrigin(tileX: x + 1, tileY: y + 1)
let bottomLeft = MapTile.locationOrigin(tileX: x, tileY: y + 1)
return [
topLeft,
topRight,
bottomRight,
bottomLeft
]
}
}
any ideas why this happens?
Post not yet marked as solved
I'm messing about with the new Look Around APIs in iOS 16, and can't seem to find a way to do a few things:
Hide the current location label that shows up at the bottom of the Look Around view
Go straight into the Look Around view rather than having to tap into it with the button
Overlay a view on top of the Look Around view when panning/movement is active (the view seems to take highest priority and I cannot override it)
Get it running on MacOS (as an iPad app)
struct LookAroundView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> some UIViewController {
let viewController = MKLookAroundViewController()
viewController.badgePosition = .topLeading
viewController.isNavigationEnabled = true
viewController.pointOfInterestFilter = .excludingAll
viewController.showsRoadLabels = false
viewController.title = "Round 1"
let location = CLLocationCoordinate2D(
latitude: 37.80770,
longitude: -122.47207
)
let sceneRequest = MKLookAroundSceneRequest(coordinate: location)
Task {
do {
viewController.scene = try await sceneRequest.scene
} catch {
viewController.scene = nil
}
}
return viewController
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
}
Post not yet marked as solved
Getting the crash only in iOS 15.x and i cannot identify the reason.
Log:
0 VectorKit 0x20ace0 gss::BaseRenderStyle<gss::CartoStyle<gss::PropertyID> >::attributeMatch(geo::intern_vector<gss::StyleCondition, geo::StdAllocator<gss::StyleCondition, gss::Allocator> > const&, std::__1::unordered_map<gss::StyleAttribute, unsigned short, std::__1::hash<gss::StyleAttribute>, std::__1::equal_to<gss::StyleAttribute>, geo::StdAllocator<std::__1::pair<gss::StyleAttribute const, unsigned short>, gss::Allocator> > const&) const + 48
1 VectorKit 0x2f5ac4 unsigned int const& gss::RenderStyle<gss::PropertyID>::styleValueForKeyAtZ<unsigned int>(gss::PropertyID, unsigned char, gss::StyleBlendingEnd) const + 168
2 VectorKit 0x3fd8b8 unsigned int gss::RenderStyle<gss::PropertyID>::valueForKeyAtZ<unsigned int>(gss::PropertyID, unsigned char) const + 232
3 VectorKit 0xb944 md::RoadBatch::setRenderOrdersForStrokeAndFill(bool, ggl::RenderItem*, ggl::RenderItem*, ggl::RenderItem*, ggl::RenderItem*, ggl::RenderItem*, unsigned int, bool, std::__1::shared_ptr<gss::StylesheetQuery<gss::PropertyID> > const&, md::RibbonLayoutContext const&, unsigned char) + 184
4 VectorKit 0x79c7d4 md::RoadBatch::layout(md::RoadLayoutContext const&) + 1568
5 VectorKit 0x79f1d8 md::RibbonLayer<md::Ribbons::RoadRibbonDescriptor>::layoutBatches(md::RoadLayoutContext const&) + 56
6 VectorKit 0x57354 md::RoadRenderLayer::layout(md::LayoutContext const&) + 1256
7 VectorKit 0xb2c80 std::__1::__function::__func<md::CartographicRenderLayer::frame(md::LayoutContext const&)::$_0, std::__1::allocator<md::CartographicRenderLayer::frame(md::LayoutContext const&)::$_0>, void ()>::operator()() + 112
8 VectorKit 0x59f95c invocation function for block in geo::TaskQueue::queueAsyncTask(std::__1::shared_ptr<geo::Task>, NSObject<OS_dispatch_group>*) + 108
9 libdispatch.dylib 0x2914 _dispatch_call_block_and_release + 32
10 libdispatch.dylib 0x4660 _dispatch_client_callout + 20
11 libdispatch.dylib 0xbde4 _dispatch_lane_serial_drain + 672
12 libdispatch.dylib 0xc98c _dispatch_lane_invoke + 444
13 libdispatch.dylib 0xdc74 _dispatch_workloop_invoke + 1796
14 libdispatch.dylib 0x171a8 _dispatch_workloop_worker_thread + 656
15 libsystem_pthread.dylib 0x10f4 _pthread_wqthread + 288
16 libsystem_pthread.dylib 0xe94 start_wqthread + 8
Post not yet marked as solved
Does Mapkit support Speed Limit API as Google does?
Thanks
Post not yet marked as solved
Hi
I am developing an app with swiftUI. Here is the code of a map view. I create customized annotations and show them on the map view. The issue is that when I drag or zoom in/ out on the map view. The app is so slow. The fps decrease to about 20 - 30 from 60. I use instruments to analyze this app. The result shows that there are thousands of times annotation render. I think that the reason for this issue may be off-screen rendering. But I don't know how to solve it. Looking forward to your help.
swift
Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true, userTrackingMode: $trackingMode, annotationItems: result, annotationContent: { mark in
MapAnnotation(coordinate: CLLocationCoordinate2D(latitude: mark.lat, longitude: mark.long)) {
Button {withAnimation {
self.selectedGymUid = Int(mark.uid)
}} label: {RoundedGymIconOnMapView(name:mark.name)
.clipShape(Circle())
.overlay(Circle().stroke(selectedGymUid == Int(mark.uid) ? Color(.green).opacity(0.5) : AppColor.shared.joggingColor.opacity(0.5),lineWidth: 1.4))
.scaleEffect(selectedGymUid == Int(mark.uid) ? 2 : 1)
.shadow(radius: 5) }
}
})
Post not yet marked as solved
I try to develop an indoor map program by IMDF. Before starting, I want to ask, does anyone know the development process? Mainly want to know at which stage the map data needs to be uploaded to the Apple server?(or unnecessary?)
I mean, For the conversion between GeoJSON and IMDF, the data only be uploaded to the Apple server for conversion?
Hi,
I am faced with a strange problem with a Catalyst app that uses MapKit.
If the map is visible and I resize the window (causing the map the resize), sometime the app crashes with some Metal related error.
Is this a know issue between MapKit and Catalyst?
There is something I can do in order to prevent this crash?
Below you can find the error message and a screenshot of the thread that caused the crash.
Thank you
-[MTLDebugDevice notifyExternalReferencesNonZeroOnDealloc:]:2951: failed assertion `The following Metal object is being destroyed while still required to be alive by the command buffer 0x7f96de27f600 (label: <no label set>):
<MTLToolsObject: 0x7f96dde552e0> -> <BronzeMtlTexture: 0x7f96dc04c230>
label = <none>
textureType = MTLTextureType2D
pixelFormat = MTLPixelFormatBGRA8Unorm_sRGB
width = 2372
height = 1668
depth = 1
arrayLength = 1
mipmapLevelCount = 1
sampleCount = 1
cpuCacheMode = MTLCPUCacheModeDefaultCache
storageMode = MTLStorageModeManaged
hazardTrackingMode = MTLHazardTrackingModeTracked
resourceOptions = MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModeManaged MTLResourceHazardTrackingModeTracked
usage = MTLTextureUsageShaderRead MTLTextureUsageRenderTarget
shareable = 0
framebufferOnly = 0
purgeableState = MTLPurgeableStateNonVolatile
swizzle = [MTLTextureSwizzleRed, MTLTextureSwizzleGreen, MTLTextureSwizzleBlue, MTLTextureSwizzleAlpha]
isCompressed = 0
parentTexture = <null>
parentRelativeLevel = 0
parentRelativeSlice = 0
buffer = <null>
bufferOffset = 0
bufferBytesPerRow = 0
iosurface = 0x0
iosurfacePlane = 0
allowGPUOptimizedContents = YES'
Post not yet marked as solved
Recently I am working on an AR navigation app. I have tried to use a library call ARCL which is downloaded from Cocoapods. I can plot out a route in AR. However, the route is always jumping around when i am walking. Is there any way that I can make the route be stable and stick on the ground. Hope can someone help me.
This is what I have done so far
Post not yet marked as solved
When using MKMapView within SwiftUI in MacOS, via NSViewRepresentable and a Coordinator, the are several console messages per second "CVDisplayLinkSetPaused", alternating between [TRUE]and [FALSE] when displaying a poly line and/or annotations. This is possibly preventing NSClickGestureRecognizer from working correctly, although that's probably another, developer (my), issue. These console messages have only occurred in the last two Mac OS beta releases, the last being 21D5039d. Even if these messages are not an indication of a problem, they are very distracting and annoying - taking up so much time and space in the logs.
Feedback submitted: FB9845486
Post not yet marked as solved
As I currently live in ReactNative Hell, I like to flesh out all my native iOS demos and samples to the max. Including things like accessibility. Recently, I wrote a very simple demo containing a map, and I stumbled upon some issues I was unable to resolve. I think they present very general usecases, and so I would be happy if anyone of you had any idea.
The condensed source code for the issues can be found on GitHub
Issue 1: The Phantom Overlay
To reproduce Run the app on a device, and be sure that VoiceOver is on. Swipe right to get to the Annotations.
Expected Result The title of the annotation is read.
Actual Result The title of the annotation is read twice.
What I know For every annotation on the map view, there is also an overlay, an MKCircle, generated by an MKCircleRenderer. When this overlay is not present, the title is — correctly — only read once.
What I have tried In ViewController.swift, lines 54 and 92, I have set both the overlay's and the renderer's isAccessibilityElement property to false. This does not fix the issue (probably because neither of them are the actual views).
The overlay should never be an accessible element. Any information should be encoded in the annotation (e.g. "There is a 10m region around this marker")
Issue 2: The Unknown Trait
While it is correct that the title of the annotation should be read, there is no indication that the annotation can be clicked or interacted with. I have set annotationView.accessibilityTraits = [.button], but this does not change anything. My expectation would be "Cologne Cathedral, Button" or a similar hint that the item is clickable.
Issue 3: The Unreachable Callout
With VoiceOver active, click on an annotation. I have taken some hints from Stackoverflow, and tried to disable the accessibility on the annotation, and enable it on the callout. This leads to the callout being reachable somehow, but it is absolutely not obvious if you can not see the screen.
How can I indicate to the VoiceOver user that now a callout is being shown?
A Working Extra: The Annotation Rotor
The app also contains a custom rotor, to go through the annotations one by one, without also reading the default Points-Of-Interest on the map. Interestingly (or maybe rather as expected), the title of the annotation is correctly only read once.
I whould be extremely happy to get some feedback on these issues, it sounds like most of them could be rather common.
Thanks!
Alex
Post not yet marked as solved
Hello everyone, I wanna take user speed in km. How can I take ?
Post not yet marked as solved
Using the new version Xcode 13.0 beta, exception throws when init apple map view in Simulator
self.mapView = MKMapView()
'NSInvalidArgumentException', reason: '-[MTLDebugDevice traceStream]: unrecognized selector sent to instance 0x7f946af781d0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff203f6fa7 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff2019cbe7 objc_exception_throw + 48
2 CoreFoundation 0x00007fff20405b28 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x00007fff203fb46b forwarding + 1412
4 CoreFoundation 0x00007fff203fd598 _CF_forwarding_prep_0 + 120
5 libMTLCapture.dylib 0x0000000105f65a0e libMTLCapture.dylib + 55822
6 libMTLCapture.dylib 0x0000000105f6425d libMTLCapture.dylib + 49757
7 VectorKit 0x00007fff3181cf7d -[MetalLayer initWithDevice:sRGB:] + 73
8 VectorKit 0x00007fff30fcd059 _ZNK2md6Device8newLayerEv + 179
9 VectorKit 0x00007fff315cf63d -[MDDisplayLayer createRenderTarget] + 110
10 VectorKit 0x00007fff31015cf9 -[VKMapView _createDisplayLayer] + 36
11 VectorKit 0x00007fff3101c8b9 -[VKMapView initShouldRasterize:inBackground:contentScale:auditToken:mapViewPurpose:] + 1575
12 MapKit 0x00007fff30b08f22 -[MKBasicMapView initWithFrame:andGlobe:shouldRasterize:] + 408
13 MapKit 0x00007fff30a226ee -[MKMapView _commonInitFromIB:gestureRecognizerHostView:locationManager:showsAttribution:showsAppleLogo:] + 1601
14 MapKit 0x00007fff30a23448 -[MKMapView initWithFrame:] + 251
15 UIKitCore 0x00007fff254abce5 -[UIView init] + 44
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/jli1/Library/Developer/Xcode/DerivedData/erpclfvpzelgfubxbfquzihyqiou/Build/Products/Debug-iphonesimulator:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMTLCapture.dylib
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MTLDebugDevice traceStream]: unrecognized selector sent to instance 0x7f946af781d0'
terminating with uncaught exception of type NSException
CoreSimulator 772.1 - Device: iPhone 12 Pro (E9648567-BCB1-4314-A315-3B0C8B142328) - Runtime: iOS 15.0 (19A5261u) - DeviceType: iPhone 12 Pro
Post not yet marked as solved
I have been trying to find some documentation on how to add an overlay to a map with the new SwiftUI Map view. There is so much here and it can be difficult to locate the proper apis for everything. Thanks for any help you all have.
Post not yet marked as solved
I'm trying to get a new value on annotationView.center. And it sometimes returns the last location that I have already got. It was working fine before iOS 15.3. But after iOS 15.3 update, it started to be intermittent.
Code:
[NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let annotationView = object as? MKAnnotationView {
let position = annotationView.center
}
}
Post not yet marked as solved
I'm working on a navigation app and I would like to snap the userLocation to the MKRoute's Polyline much like how Apple does in Apple Maps. I've added the route's MKPolyline to my MKMapView and it looks great, the user's location is just usually not centered on the road or is off to the side a bit even when using kCLLocationAccuracyBestForNavigation as the CLLocationManager's accuracy. I need it to be centered like Apple Maps as shown bellow.
How would I go about doing this? Is there a way to snap MKAnnotation's to roads (or MKPloylines) and update with the CLLocationManager's userLocation?
Post not yet marked as solved
When closing the lines of a polygon that is being drawn on the map using MapKit, we observe that the polygon is no longer closing. We didn't have any changes in the application and it stopped working after the iOS version 15.3 update. Until the previous versions it worked normally.
if (mainGleba.tamanhoArea != nil && mainGleba.tamanhoArea! > 0) {
if let areaText = formatter.string(from: mainGleba.tamanhoArea!) {
print("Área text: \(areaText)")
areaSize = sizeArea as! Double
textFieldArea.text
= "\(areaText.replacingOccurrences(of: ",", with:
".").formatToLocalCurrency(with: 2)) \.
(mainGleba.unidadeMedidaArea!)"
}
}else{
if let areaText = formatter.string(from: sizeArea) {
print("Área text: \(areaText)")
areaSize = sizeArea as! Double
textFieldArea.text
= "\(areaText.replacingOccurrences(of: ",", with:
".").formatToLocalCurrency(with: 2)) \
(mainGleba.unidadeMedidaArea!)"
}
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let polygonView = MKPolygonRenderer(overlay: overlay)
polygonView.strokeColor = Color.white()
if let _ = overlay as? MKPolygon{
polygonView.fillColor = Color.set(Color.white(), alpha: 0.2)
}
if(isAreaEnquadrada){
polygonView.strokeColor = Color.blue().withAlphaComponent(0.5)
polygonView.fillColor = Color.blue().withAlphaComponent(0.3)
}
polygonView.lineWidth = 2.0
polygonView.lineCap = CGLineCap.****
isAreaEnquadrada = false
return polygonView
}
Post not yet marked as solved
I search places with the MKLocalSearchCompleter and refine the results when the tableView cell is selected. When a MKLocalSearchCompletion is selected and MKLocalSearch.Request() is started, I get these Errors (example selects Los Angeles):
According to my research this is a very rare problem?! [SearchAttribution] No matching attribution source found for org.volunteermatch ... (+4 other domains)
Error loading attribution info for identifier org.volunteermatch from geod: Error Domain=GEOErrorDomain Code=-8 "No matching attribution source found for org.volunteermatch" UserInfo={NSDebugDescription=No matching attribution source found for org.volunteermatch} ... (+4 other domains)
These are the instance variables in a TableViewController:
var searchCompleter = MKLocalSearchCompleter()
var searchResults = [MKLocalSearchCompletion]()
This code is running everytime the search term is changed:
searchCompleter.queryFragment = text
searchCompleter.resultTypes = .address
searchCompleter.region = region
In tableView … didSelectRowAt… this code is executed:
let selectedItem = searchResults[indexPath.row]
let searchRequest = MKLocalSearch.Request()
searchRequest.naturalLanguageQuery = selectedItem.title
searchRequest.resultTypes = .address
let search = MKLocalSearch(request: searchRequest)
search.start { (response, error) in
guard let coordinate = response?.mapItems[0].placemark.coordinate else {
return
}
// send to mainVC
self.delegate?.userSelectedPlace(coordinate: coordinate)
}
Dear MapKit Team,
For my current project I'd like to include additional custom 3D geometries to a MapView alike 3D landmarks (e.g. London Eye). Think of it as adding 3D stages to a concert area or balloons, etc. Preferably alike annotations with given coordinates and altitudes.
So far I haven't seen anything comparable. Is it yet supported?
Kind regards,
Moritz
Post not yet marked as solved
Hi,
I have a controller where the user can search for map locations or points of interest by typing inside a search box.
To retrieve the list of results I set the queryFragment parameter of a MKLocalSearchCompleter with the search content.
This correctly gives me back a list of MKLocalSearchCompletion of locations and points of interest.
When a user tap on one of this locations, I need to load the coordinates.
In order to do that I do a MKLocalSearch passing the selected MKLocalSearchCompletion, like so:
let item = items[indexPath.row]
let request = MKLocalSearch.Request(completion: item)
let search = MKLocalSearch(request: request)
search.start { (response, error) in
//Do stuff with the result.
//For some specific items I receive an MKErrorDomain 4 error.
}
This works most of the time, but for some specific items the MKLocalSearch call return the error:
Error Domain=MKErrorDomain Code=4 "(null)" UserInfo={MKErrorGEOError=-8}
This error correspond to "placemarkNotFound", ie MapKit is not able to find a placemark for the specific MKLocalSearchCompletion.
I just don't understant why this should be the case.
The MKLocalSearchCompletion is returned by MapKit.
If it is returned by MapKit then a corresponding placemark should exist, right?
Why then is MapKit unable to perform a local search on it?
The problem now is that I present the user with a list of completions returned by MapKit but tapping some of them nothing happens because I cannot determine their respective coordinates.
Why is the search failing sometime? I miss something?
Thank you
Post not yet marked as solved
Hi Apple MapKit team,
I am a new iOS developer and recently learned SwiftUI. This WWDC is my first one.
I noticed that although Apple is moving towards SwiftUI, the new features released for MapKit is still largely UIKit based. I am not very familiar with UIKit. I wondered that if MapKit team is going to mainly develop in MapKit space instead of the SwiftUI space.
Cheers,