Post not yet marked as solved
I want to show what direction a user is facing (the blue cone that you get in Apple Maps), but I can't find a way to show it with SwiftUI. The closest I've found is this init signature for UserAnnotation: https://developer.apple.com/documentation/mapkit/userannotation/4235435-init
But it only gives heading data once you press the map orientation button, to always show the forward direction. I want to show the cone in the normal map, without reorienting it.
Post not yet marked as solved
I am trying to load and view several locations onto a map from a JSOPN file in my SwiftUI project, but I continually encounter the error "no exact matches in call to initializer" in my ContentView.swift file.
What I Am Trying to Do:
I am working on a SwiftUI project where I need to display several locations on a map. These locations are stored in a JSON file, which I have successfully loaded into Swift. My goal is to display these locations as annotations on a Map view.
JSON File Contents:
coordinates: latitude and longitude
name: name of the location
uuid: unique identifier for each location
Code and Screenshots:
Here are the relevant parts of my code and the error I keep encountering:
import SwiftUI
import MapKit
struct ContentView: View {
@State private var mapPosition = MapCameraPosition.region(
MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
)
)
@State private var features: [Feature] = []
var body: some View {
NavigationView {
Map(position: $mapPosition, interactionModes: .all, showsUserLocation: true) {
ForEach(features) { feature in
Marker(coordinate: feature.coordinate) {
FeatureAnnotation(feature: feature)
}
}
}
.onAppear {
POILoader.loadPOIs { result in
switch result {
case .success(let features):
self.features = features
case .failure(let error):
print("Error loading POIs: \(error.localizedDescription)")
}
}
}
.navigationBarTitle("POI Map", displayMode: .inline)
}
}
}
struct FeatureAnnotation: View {
let feature: Feature
var body: some View {
VStack {
Circle()
.strokeBorder(Color.red, lineWidth: 2)
.background(Circle().foregroundColor(.red))
.frame(width: 20, height: 20)
Text(feature.name)
}
}
}
I have not had any luck searching for solutions to my problems using the error messages that keep arising. Does anyone have any advice for how to move forward?
Map(initialPosition: .camera(mapCamera)) {
Marker("Here", coordinate: location)
}
.frame(height: 300)
.clipShape(RoundedRectangle(cornerSize: CGSize(width: 10, height: 10)))
.onMapCameraChange(frequency: .continuous) { cameraContext in
locationManager.location = cameraContext.camera.centerCoordinate
}
.onReceive(locationManager.$location, perform: { location in
if let location {
mapCamera.centerCoordinate = location
}
})
class LocationDataManager: NSObject, CLLocationManagerDelegate, ObservableObject {
enum LoadingState {
case loading
case notLoading
case finished
}
static let shared = LocationDataManager()
private let locationManager = CLLocationManager()
@Published var location: CLLocationCoordinate2D? = nil
@Published var loading: LoadingState = .notLoading
override init() {
super.init()
locationManager.delegate = self
}
func resetLocation() {
loading = .notLoading
location = nil
}
func getLocation() {
locationManager.requestLocation()
loading = .loading
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
location = locations.first?.coordinate
if location != nil {
loading = .finished
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) {
print("Failed to retrieve location: \(error.localizedDescription)")
loading = .notLoading
}
}
So the when the LocationButton is selected, the location is found and the marker is set correctly. You can also move the camera around to adjust the marker position, which works correctly. However, if you press the LocationButton again, it updates the marker position but it won't move the MapCamera to the new location. I can see the marker move. mapCamera.centerCoordinate = location should be doing it, but it's not. Anyone know how to fix this?
Post not yet marked as solved
How to use Custom URLSession in MKMapView?
Post not yet marked as solved
Searching for nearby POIs using MKLocalPointsOfInterestRequest has been unsuccessful with error Error Domain=MKErrorDomain Code=5 "(null)" UserInfo={MKErrorGEOError=-10}. Is there any solution?
Post not yet marked as solved
Hello everyone,
I have a SwiftUI application with a view containing a MapKit map as UIViewRepresentable.
I'm experience the following issue with regionDidChangeAnimated that seems related to MapKit itself as I was able to reproduce it also on another application I'm developing.
The problem is that regionDidChangeAnimated is not getting called when zooming in or out, but it's getting called for other gestures, like panning and moving the map.
This is what I noticed:
I zoom in/out on the map
regionWillChangeAnimated is called
I release my fingers from the map
regionDidChangeAnimated is NOT called
If I move a bit the map -> regionDidChangeAnimated is called ( for the previous touch ), then regionWillChangeAnimated related to the new touch is called, regionDidChangeAnimated for the new touch is called.
So it looks like when zooming in/out, regionDidChangeAnimated is lagging and not called until a new touch happens.
Did you ever experienced this behavior?
Thank you in advance for your support
Post not yet marked as solved
Seeing the following, whether initializing Maps() in SwiftUI or using Apple's example Overlay Project since updating to Xcode 15.3:
Thread Performance Checker: Thread running at User-interactive quality-of-service class waiting on a thread without a QoS class specified (base priority 0). Investigate ways to avoid priority inversions
PID: 2148, TID: 42369
Backtrace
=================================================================
3 VectorKit 0x00007ff81658b145 ___ZN3geo9TaskQueue5applyEmNSt3__18functionIFvmEEE_block_invoke + 38
4 libdispatch.dylib 0x00000001036465c2 _dispatch_client_callout2 + 8
5 libdispatch.dylib 0x000000010365d79b _dispatch_apply_invoke3 + 527
6 libdispatch.dylib 0x000000010364658f _dispatch_client_callout + 8
7 libdispatch.dylib 0x0000000103647c6d _dispatch_once_callout + 66
8 libdispatch.dylib 0x000000010365c89b _dispatch_apply_redirect_invoke + 214
9 libdispatch.dylib 0x000000010364658f _dispatch_client_callout + 8
10 libdispatch.dylib 0x000000010365a67f _dispatch_root_queue_drain + 1047
11 libdispatch.dylib 0x000000010365af9d _dispatch_worker_thread2 + 277
12 libsystem_pthread.dylib 0x00000001036e2b43 _pthread_wqthread + 262
13 libsystem_pthread.dylib 0x00000001036e1acf start_wqthread + 15```
Post not yet marked as solved
Good afternoon, I'd like to get detailed information about the price usage of the Apple Map in my app in IOS (Swiftui for Iphone and Ipad). I'd like to establish a future price for the app subscription and to do that I need to obtain the precise prices for opening the map, consulting Map items, creating routes, the price of each consulting, and any other price that is related to the map usage process.
I have been searching for this information and it has not been easy to find answers. I appreciate it if I could get the information.
Best regards,
Marcello Lima
Post not yet marked as solved
I am trying to load an auxiliary window from an AppKit bundle that loads a NSViewController from a storyboard. This NSViewController displays a MKMapView.
I want to avoid supporting multiple windows from my Catalyst app so I do not want to load this window via a SceneDelegate, and that is why I have chosen to go the AppKit bundle route.
If I load a similar view controller which contains a single label, then all works as expected.
However, if I try to load a view controller with the MKMapView, I get the following error after crashing:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKMapView nsli_piercingToken]: unrecognized selector sent to instance 0x15410f600'
DropBox link to sample app with buttons on a view to select either the "Map View" (crashing) or the "Label View" (working):
https://www.dropbox.com/scl/fi/q9daurhzqvil9o2ry6k1t/CatalystMap.zip?rlkey=yjbqfn6uxfrfh1jgsdavagta7&dl=0
Post not yet marked as solved
Hi there,
I am trying to develop a country guessing game using MapKit and GeoJSON data. I have verified that my data creates the outline of the country properly using other methods, but I run into an error where the map clips and does not show portions of the countries or islands when zooming at certain levels of the map. I receive the warnings in the terminal "Mismatching number of indices, indexCount: 30, triangulatedIndexCount: 27" and "Triangulator failed to fully triangulate polygon: (0.1296, 0.303328), (0.108053, 0.296605), (0.0671644, 0.289883), (0.0586311, 0.281121), (0.0397156, 0.27289), (0.0323911, 0.262393), (0.0610489, 0.260732), (0.102507, 0.284671), (0.140053, 0.292602), (0.133511, 0.291167), (0.137707, 0.293659), (0.138489, 0.29872)" I am not sure what these tuple values are, or how to fix the errors, as I have adjusted my data (removing duplicate coordinates, refreshing the map, etc). How am I able to counteract these warnings, or at least get a sense of what they are asking?
Post not yet marked as solved
Is it possible to programmatically force iphone to use cellular internet during WIFI connection?
I am connected via WIFI to a device with no internet connection. But I need to use MapKit
Post not yet marked as solved
Hello, I have a question.
I have a LookAroundPreview, that loads correctly a scene, and when I tap on it, it natively shows a view I can navigate in, and that I can close. All that is ok.
However, when I want to display that same LookAroundPreview in a fullScreenCover (because my app needs it for navigation purposes), it directly shows the navigatable View with the closeButton. That I don't want.
Is there an option to pass, that I missed? Is this a bug of the LookAroundPreview? Or is this wanted by Apple devs?
Thank you very much for your help,
Sincerely
import SwiftUI
struct ContentView: View {
@State private var displayFullScreen = false
//AppleLookAroundView is just a wrapper around native LookAroundPreview, that loads a NYC coordinate
var body: some View {
VStack {
AppleLookAroundView()
Spacer()
Button("Display fullScreen cover") {
displayFullScreen = true
}
Spacer()
}
.fullScreenCover(isPresented: $displayFullScreen) {
VStack {
AppleLookAroundView()
Text("⬆ It somehow detects it is in a fullScreenCover and unwantingly change its display")
}
}
}
}
import SwiftUI
import MapKit
import CoreLocation
struct AppleLookAroundView: View {
@State private var scene: MKLookAroundScene?
let coordinate = CLLocationCoordinate2D(latitude: 40.651238394229324, longitude: -73.96432239237737)
var body: some View {
LookAroundPreview(scene: $scene, allowsNavigation: true, badgePosition: .bottomTrailing)
.task {
do {
scene = try await fetchScene(for: coordinate)
} catch {
print("Couldn't fetch scene")
}
}
.frame(height: 300)
}
private func fetchScene(for coordinate: CLLocationCoordinate2D) async throws -> MKLookAroundScene? {
let lookAroundScene = MKLookAroundSceneRequest(coordinate: coordinate)
let scene = try await lookAroundScene.scene
return scene
}
}
![]("https://developer.apple.com/forums/content/attachment/a10a7701-dd8c-4d83-9a03-848cf0373417" "title=Capture d’écran 2024-04-24 à 12.56.46.png;width=898;height=1860")
``
![]("https://developer.apple.com/forums/content/attachment/d54f7fe1-aac8-4280-ab97-663f0bdd440f" "title=Capture d’écran 2024-04-24 à 12.56.34.png;width=924;height=1882")
`
Post not yet marked as solved
I'm developing an iOS app that displays store locations on a map using Apple Maps (MapKit). I've limit the number of icons that can be displayed on the map to 100, but there's still huge performance issues and the app is very laggy even on modern iPhone models. What's the best practice when displaying a large number of icons on a map, should the icons be in PNG format with a small resolution (~10kb) or should the icons be vector (SVG) for best performance? Should I use the MapKit framework for iOS 17 or the UIKit approach?
Post not yet marked as solved
Any suggestions on how to display multi-polygons within MapKit for SwiftUI(https://developer.apple.com/documentation/mapkit/mappolygon)?
At the moment it is not supported and only supported by MapKit for UIKit(https://developer.apple.com/documentation/mapkit/mkmultipolygon) . Any idea on how to bridge these over?
Post not yet marked as solved
On iPhone 14 Pro running iOS 17.4.1, tapping on MKMapView triggers a dozen or more additional hitTest calls. At the moment, only one device has encountered this issue.Not sure if it's a hardware issue or a bug with MKMapView.
Adding MKMapView to the app could potentially cause multiple hitTest calls on views across other pages.
Post not yet marked as solved
I have a problem getting cg point from coordinate with MKsnapshotter.
It works well with .flyover or .satellite map type but when using .satelliteFlyover cg point gets invalid value.
Can you guys help me to get correct value?
I attach screenshot here.
Post not yet marked as solved
Using SwiftUI, MapKit and the Map() view in iOS 17, I'm adding markers and annotations to the map instance. However it seems regardless of what order they are added, they are rendered with random Z-index values. I've not found any modifiers to specify any kind of priority.
Is there a way to declare Z-index priority of Marker and Annotation views?
Post not yet marked as solved
I have more than 2000 location pins in SwiftData.
My model like this:
@Model
class HaritaModel {
let id: Int
let sto_title: String
let sto_latitude: Double
let sto_longitude: Double
let sto_address: String
let sto_city: String
let sto_country: String
init(id: Int, sto_title: String, sto_latitude: Double, sto_longitude: Double, sto_address: String, sto_city: String, sto_country: String) {
self.id = id
self.sto_title = sto_title
self.sto_latitude = sto_latitude
self.sto_longitude = sto_longitude
self.sto_address = sto_address
self.sto_city = sto_city
self.sto_country = sto_country
}
}
I want to take the user's location and show them the pins at a certain distance. I want these pins to be dynamically updated when the user pan or zoom the map.
The code I am trying to write is as follows:
//
// HaritaTest.swift
//
import SwiftUI
import MapKit
import SwiftData
struct HaritaTest: View {
@Environment(\.modelContext) private var contextHarita
@Query private var harita: [HaritaModel]
@State private var userPosition: MapCameraPosition = .userLocation(fallback: .automatic)
@State private var userCoordinate: CLLocationCoordinate2D?
var body: some View {
Text("Total Boutique \(harita.count)")
Map(initialPosition: { userPosition }) { haritaView in
ForEach(harita) { point in
if let userCoordinate = userCoordinate,
let stoLatitude = point.sto_latitude,
let stoLongitude = point.sto_longitude,
let latitude = Double(stoLatitude),
let longitude = Double(stoLongitude) {
let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
if haritaView.contains(coordinate: coordinate) {
MapPin(coordinate: coordinate)
}
}
}
}
.onAppear {
CLLocationManager().requestWhenInUseAuthorization()
getUserLocation()
}
}
private func getUserLocation() {
if let userLocation = CLLocationManager().location {
userCoordinate = userLocation.coordinate
}
}
}
struct HaritaTest_Previews: PreviewProvider {
static var previews: some View {
HaritaTest()
}
}
can you support me?
thanks in advance
Post not yet marked as solved
Is there a possibility to enable the public transport layer like in the Maps app?
Post not yet marked as solved
We're recently requested a Mapkit JS / Mapkit Server api limit increase request and are waiting to hear back before we push an important update to our app which switches to mapkit via server apis.
We don't often go over the 25k daily limit, but there can be spikes where the app goes very viral and we'll need well over 25k – likely above 50k based on historic usage.
I was wondering if there's any way to expedite our limit request? Or how do we get notified if our limit has been approved, is there any way to check?
Would using one of our Code-level support requests (TSIs) be a good idea here?
Thanks!