2016-01-16 161 views
1

我很難弄清楚當用戶點擊指向當前位置的註釋時如何顯示註釋標題。除此之外,一切工作都很好。我使用的CLLocationManagerhttps://github.com/varshylmobile/LocationManager包裝,但我不認爲它影響Mapbox,因爲我可以在地圖上正確顯示我的引腳。Mapbox iOS SDK 3 - 註釋標題在註釋被點擊時不顯示

這裏的截圖樣本:

Mapbox with 2 annotations

正如你所看到的,我可以運行沒有任何問題的應用程序。只是當我將一些註釋標題和副標題設置到引腳上,並在運行時點擊它時,它不會顯示任何內容。

這裏是我的註釋代碼片段:

 let point = MGLPointAnnotation() 
     point.coordinate = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude) 
     point.title = "Hello world!" 
     point.subtitle = "Welcome to The Ellipse." 

     self.mapView.addAnnotation(point) 

     let point2 = MGLPointAnnotation() 
     point2.coordinate = CLLocationCoordinate2D(latitude: 37.43259552, longitude: location.coordinate.longitude) 
     point2.title = "Hello world!" 
     point2.subtitle = "Welcome to The Ellipse." 

     self.mapView.addAnnotation(point2) 

     self.mapView.selectAnnotation(point, animated: true) 
     self.mapView.showAnnotations([point, point2], animated: true) 

,這裏是呼出功能:

func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { 
    return true 
} 

func mapView(mapView: MGLMapView, imageForAnnotation annotation: MGLAnnotation) -> MGLAnnotationImage? { 
    return nil 
} 

我在iOS 9.2時,Xcode 7

謝謝!

回答

3

實例化我的地圖視圖後,我忘記了這行代碼。

mapView.delegate = self 

謝謝!

+0

我有此相同的問題!謝謝! – SMPLGRP

2

如何配置與Mapbox iOS的SDK基礎標註的觀點Here's an example

import Mapbox 

class ViewController: UIViewController, MGLMapViewDelegate { 

    var mapView: MGLMapView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     mapView = MGLMapView(frame: view.bounds) 
     mapView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] 

     view.addSubview(mapView) 

     // remember to set the delegate (or much of this will not work) 
     mapView.delegate = self 

     addAnnotation() 
    } 

    func addAnnotation() { 
     let annotation = MGLPointAnnotation() 
     annotation.coordinate = CLLocationCoordinate2DMake(35.03946, 135.72956) 
     annotation.title = "Kinkaku-ji" 
     annotation.subtitle = "\(annotation.coordinate.latitude), \(annotation.coordinate.longitude)" 

     mapView.addAnnotation(annotation) 

     // fit the map to the annotation(s) 
     mapView.showAnnotations(mapView.annotations!, animated: false) 

     // pop-up the callout view 
     mapView.selectAnnotation(annotation, animated: true) 
    } 

    func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { 
     return true 
    } 

    func mapView(mapView: MGLMapView, leftCalloutAccessoryViewForAnnotation annotation: MGLAnnotation) -> UIView? { 
     if (annotation.title! == "Kinkaku-ji") { 
      let label = UILabel(frame: CGRectMake(0, 0, 60, 50)) 
      label.textAlignment = .Right 
      label.textColor = UIColor(red: 0.81, green: 0.71, blue: 0.23, alpha: 1) 
      label.text = "金閣寺" 

      return label 
     } 

     return nil 
    } 

    func mapView(mapView: MGLMapView, rightCalloutAccessoryViewForAnnotation annotation: MGLAnnotation) -> UIView? { 
     return UIButton(type: .DetailDisclosure) 
    } 

    func mapView(mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) { 
     // hide the callout view 
     mapView.deselectAnnotation(annotation, animated: false) 

     UIAlertView(title: annotation.title!!, message: "A lovely (if touristy) place.", delegate: nil, cancelButtonTitle: nil, otherButtonTitles: "OK").show() 
    } 
}