For the first time, Mapview renders annotations properly with correct annotation and cluster annotations.
After first time, when user Zoom Out or Pans out then will fetch additions hotspots based on the region changes. In this scenario, mapview shows like 5 individual annotations overlapping each other and when I tap on the annotation it merge back and form a cluster annotation.
Registering Annotation View
Swift
mapView.register(WifiAnnotationView.self, forAnnotationViewWithReuseIdentifier: WifiAnnotationView.reuseID)
mapView.register(ClusterWifiAnnotationView.self, forAnnotationViewWithReuseIdentifier: ClusterWifiAnnotationView.reuseID)
SingleAnnotationView
Swift
class SingleAnnotationView: MKAnnotationView {
static let reuseID = "SingleAnnotationView"
lazy var subTitleLabel: UILabel = {
let subTitle = UILabel()
subTitle.numberOfLines = 0
return subTitle
}()
override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
super.init(annotation: annotation, reuseIdentifier:
reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func prepareForDisplay() {
super.prepareForDisplay()
displayPriority = .defaultLow
canShowCallout = true
subTitleLabel.text = "address goes here"
detailCalloutAccessoryView = subTitleLabel
image = UIImage(named: "icon")
}
}
ClusterAnnotationView
Swift
class ClusterAnnotationView: MKAnnotationView {
static let reuseID = "ClusterAnnotation"
lazy var subTitleLabel: UILabel = {
let subTitle = UILabel()
subTitle.numberOfLines = 0
return subTitle
}()
override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
collisionMode = .circle
centerOffset = CGPoint(x: 0, y: -10)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func prepareForDisplay() {
super.prepareForDisplay()
if let cluster = annotation as? MKClusterAnnotation {
let totalWifi = cluster.memberAnnotations.count
if totalWifi 0 {
image = UIImage(named: "cluster-icon")
displayPriority = .defaultHigh
}
}
}
}
View for Annotation: MKMapview Delegate
Swift
public func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) - MKAnnotationView? {
switch annotation {
case is HotspotPoint:
let view = mapView.dequeueReusableAnnotationView(withIdentifier: WifiAnnotationView.reuseID, for: annotation)
view.clusteringIdentifier = "WifiAnnotationView"
return view
case is MKClusterAnnotation:
return mapView.dequeueReusableAnnotationView(withIdentifier: ClusterWifiAnnotationView.reuseID, for: annotation)
default:
return nil
}
}
Every time we make backend call to fetch additional annotations or new annotations then we remove entire annotations and add the new set of annotations to MapView. Please find the code below for add/remove api
Swift
mapView.removeAnnotations(mapview.annotations)
mapView.addAnnotations([newAnnotations])
Please let what's is going wrong for cluster logic not working properly.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
We recently notified from Apple that our Hotspot helper is delaying device to switch Wifi Networks. To handle this issue better, we need to refactor our code a bit handle the scenario gracefully and while reading this documentation https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/Hotspot_Network_Subsystem_Guide/Contents/AuthStateMachine.html#//apple_ref/doc/uid/TP40016639-CH2-SW1
Some questions came up while responding back to evaluate and filterscanlist command. Here are our questions
What is the lifecycle of exclude_list? Does it get cleared every time Authentication State Machine goes into Inactive State?
What happens if we send commandNotRecognized/unsupportedNetwork/temporaryFailure after evaluate command? Does our app get an evaluate command next time when device joins the same network?
What is the actual time for the app to respond to network change evaluate command? Is 45 seconds the timeout limit for app to evaluate and respond?
After responding to the evaluate command, how quickly is it terminated from running in the background?
Topic:
App & System Services
SubTopic:
Networking