Fairly new to iOS dev and I'm following the "first steps with the iOS MapBox SDK" tutorial for Swift (https://www.mapbox.com/help/first-steps-ios-sdk/). Things were fine with displaying the map, custom style, and adding an annotation. But then encountered an issue when trying to interact with the annotation to display its title and subtitle.
The print("allow")
print("tap on callout")
don't seem to ever get called. Even mapView.selectAnnotation(point, animated: true)
doesn't do anything (and it wasn't doing anything without it either)
Using xCode 8.0, MacOS Sierra, Swift 3, iOS 10
I'm a bit clueless now, any advice would be appreciated
Thanks in advance
ViewController.swift:
import UIKit
import Mapbox
class ViewController: UIViewController{
@IBOutlet var mapView: MGLMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let point = MGLPointAnnotation()
point.coordinate = CLLocationCoordinate2D(latitude: 46.082666, longitude:7.508510)
point.title = "Title"
point.subtitle = "Subtitle"
mapView.addAnnotation(point)
mapView.selectAnnotation(point, animated: true)
print("add annotation");
}
// Return `nil` here to use the default marker.
func mapView(mapView: MGLMapView, viewForAnnotation annotation: MGLPointAnnotation) -> MGLAnnotationView? {
print("default marker")
return nil
}
// Allow callout view to appear when an annotation is tapped.
func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLPointAnnotation) -> Bool {
print("allow")
return true
}
func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation) {
print("tap on callout")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Screenshot: Annotation displays where it's supposed to but cannot be interacted with