Swift 4.0 MapView Running Slow
If this is just in the simulator for ios 11 or 10.3, then it is a known bug. The XCode 9 simulator is working very slowly for everyone relating to mapKit. This bug can be seen here and here. It should, however, work fine if you use the app on your phone.
Apple staff working with Swift development have acknowledged the issue. The only workaround currently is using the ios 10 simulator or changing the rendering modules (suggested by Apple staff). Supposedly, changing the modules isnt perfect, but it might just help. Type this in terminal:
defaults write com.apple.CoreSimulator.IndigoFramebufferServices FramebufferRendererHint X
Replace the X with: 0 = auto, 1 = Metal, 2 = OpenCL, 3 = OpenGL
Again, this is an official bug in the simulator so changing the rendering still won't make the simulation perfect. There have been 4-5 people who have submitted bug reports on this and it has been acknowledged, so hopefully a fix comes soon.
Edit
I tried a map kit app on iOS 11.1 simulator. It seems to be slightly smoother but the error message still pops up... waiting for a fix
Edit
A comment pointed out that this is fixed in the iOS 11.3 beta.
How to slow down MapView animation in Swift?
You don't need to call setCenter(_:animated:)
, at this point. What you could do is to directly set a value for centerCoordinate
inside UIView
animation function:
// set your needed time per second, the current is 3.0 seconds
UIView.animate(withDuration: 3.0) {
self.mapView.centerCoordinate = annotation.coordinate
}
Tapping an MKAnnotation to select it is REALLY slow
Unfortunately, there's nothing you can do about this. It's for the exact same reason that tapping links in Mobile Safari is slow: the gesture recognizers have to jostle for a while to decide whether you might be scrolling (dragging) before they agree that you are tapping.
So, it has nothing to do with the animation. It's just the nature of gesture recognition in this situation.
Very slow scrolling/zooming experience with GMUClusterRenderer (Google Maps Clustering) on iOS
I was facing the same issue. After debugging a lot and checking google's code even, i come to the conclusion that, issue was from GMUDefaultClusterIconGenerator
. This class is creating images at runtime for given cluster size that you are displaying. So, when you zoom in or zoom out the map, the cluster size is going to update, and this class creates new image for new number(Even it keep images cached, if same number get repeated).
So, the solution that i found is to use buckets
. You will get surprised by seeing this new term. Let me explain the bucket concept by giving simple example.
suppose you kept bucket sizes as 10, 20, 50, 100, 200, 500, 1000.
- Now, if your cluster is 3, then it will show 3.
- If cluster size = 8, show = 8.
- If cluster size = 16, show = 10+.
- If cluster size = 22, show = 20+.
- If cluster size = 48, show = 20+.
- If cluster size = 91, show = 50+.
- If cluster size = 177, show = 100+.
- If cluster size = 502, show = 500+.
- If cluster size = 1200004, show = 1000+.
Now here, for any cluster size, the marker images that are going to be rendered will be from 1, 2, 3, 4, 5, 6, 7, 8, 9, 10+, 20+, 50+, 100+, 200+, 500+, 1000+. As it caches the images, so this images is going to be reused. So, the time+cpu that it was using for creating new images is lowered(only few images required to be created).
You must have got the idea, about buckets now. As, if cluster is having very small number, then cluster size matters, but if increases, then bucket size is enough to get idea about cluster size.
Now, question is how to achieve this.
Actually, GMUDefaultClusterIconGenerator
class has already this functionality implemented, you just need to change its initialisation to this:
let iconGenerator = GMUDefaultClusterIconGenerator(buckets: [ 10, 20, 50, 100, 200, 500, 1000])
GMUDefaultClusterIconGenerator
class have other init methods, by using which you can give different background colors to different buckets, different background images to to different buckets and many more.
Let me know, if any further help required.
CLLocationManager is slow getting location, Swift
Try setting the accuracy and use locationManager.startUpdatingLocation(). I do that, and get answer within a second (on the device).
Related Topics
Add Animations to Foreach Loop Elements (Swiftui)
Swift 2 Protocol Extension Not Calling Overridden Method Correctly
Swift Error Handling for Methods That Do Not Throw
How to Make Physics Bodies Stick to Nodes Anchor Points
Expandable Sections Uitableview Indexpath Swift
How to Retrieve a Random Object from Firebase Using a Sequential Id
How to Hide Labels in iOS-Charts
Warning: Initialization of 'Unsafebufferpointer<T>' Results in a Dangling Buffer Pointer
How to Drag and Drop a Sprite in Swift 3.0
Get Image from Calayer or Nsview (Swift 3)
Alamofire: Send JSON with Array of Dictionaries
How to Create a String from Utf8 in Swift
Self' Captured by a Closure Before All Members Were Initialized
How to Write a Function That Will Unwrap a Generic Property in Swift Assuming It Is an Optional Type
Localizewithformat and Variadic Arguments in Swift