所以我正在使用 Swift 4 并且希望有一个引脚掉落,然后当用户触摸该引脚时我也希望它能显示当前位置的文本...当我运行它时,引脚掉落得很好,但是之后我无法点击引脚,因此与该标记点完全没有交互。我应该注意,我正在使用 Mapbox。
import Foundation
import UIKit
import CoreLocation
import Mapbox
import MapKit
class SecondViewController: UIViewController, CLLocationManagerDelegate, MGLMapViewDelegate {
@IBOutlet var mapView: MGLMapView!
let manager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func markStuff(_ sender: Any) {
}
@IBAction func refLocation(_ sender: Any) {
manager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
mapView.setCenter(center, zoomLevel: 10, animated: true)
let annotation = MGLPointAnnotation()
annotation.coordinate = location.coordinate
annotation.title = "\(annotation.coordinate)"
self.mapView.addAnnotation(annotation)
manager.stopUpdatingLocation()
}
}
最佳答案
尝试此方法来处理 pin 上的点击
func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation)
{
// Do something here
print("Do Something here You Want)
}
另请参阅 Mapbox 文档 https://www.mapbox.com/ios-sdk/api/3.0.0/Protocols/MGLMapViewDelegate.html#//api/name/mapView:tapOnCalloutForAnnotation
关于ios - Swift:如何制作图钉放置位置的自定义标题 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46812801/