Ios 如何向MKPointAnnotation添加按钮并打开地图?

Ios 如何向MKPointAnnotation添加按钮并打开地图?,ios,swift,annotations,maps,mapkit,Ios,Swift,Annotations,Maps,Mapkit,我必须为我的特定进入点添加一个按钮,单击该按钮打开已经通过所选点坐标的地图应用程序。有人知道怎么做吗?我的密码是这个。这个图像就是我想要的 我的代码: import Foundation import UIKit import MapKit import CoreLocation class PuntiVenditaController: UIViewController, MKMapViewDelegate { @IBOutlet weak var menuButton:UIBarButt

我必须为我的特定进入点添加一个按钮,单击该按钮打开已经通过所选点坐标的地图应用程序。有人知道怎么做吗?我的密码是这个。这个图像就是我想要的

我的代码:

import Foundation
import UIKit
import MapKit
import CoreLocation

class PuntiVenditaController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var menuButton:UIBarButtonItem!
@IBOutlet weak var mapView: MKMapView!
let regionRadius: CLLocationDistance = 1000
let locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()

    if revealViewController() != nil {
        menuButton.target = revealViewController()
        menuButton.action = "revealToggle:"
        view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }

    locationManager.requestWhenInUseAuthorization()
    locationManager.startUpdatingLocation()
    let location = CLLocationCoordinate2D(latitude: 41.225891, longitude: 16.291489)

    let span = MKCoordinateSpanMake(0.05, 0.05)
    let region = MKCoordinateRegion(center: location, span: span)
    mapView.setRegion(region, animated: true)
    mapView.showsPointsOfInterest = false
    mapView.showsUserLocation = true
    displayMarkers()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func centerMapOnLocation(location: CLLocation) {
    let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
        regionRadius * 2.0, regionRadius * 2.0)
    mapView.setRegion(coordinateRegion, animated: true)
}

func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
    if control == view.rightCalloutAccessoryView{
        println(view.annotation.title) // annotation's title
        println(view.annotation.subtitle) // annotation's subttitle

        //Perform a segue here to navigate to another viewcontroller
        // On tapping the disclosure button you will get here
    }
}

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

    println("viewForannotation")
    if annotation is MKUserLocation {
        //return nil
        return nil
    }

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView

    if pinView == nil {
        //println("Pinview was nil")
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView!.canShowCallout = true
        pinView!.animatesDrop = true
    }

    var button = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton // button with info sign in it

    pinView?.rightCalloutAccessoryView = button


    return pinView
}

func displayMarkers() -> Void
{
    let annotationView = MKAnnotationView()
    // Adding button here wont do anything  so remove these two lines
    let detailButton: UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
    annotationView.rightCalloutAccessoryView = detailButton

    // For adding button we have to use a method named as viewForAnnotation
    let annotation = MKPointAnnotation()
    let name = "Title"
    let latitude = 41.225891
    let longitude = 16.291489
    annotation.title = name
    var markerLatitude: Double = latitude
    var markerLongitude: Double = longitude
    let location = CLLocationCoordinate2D(latitude: markerLatitude, longitude: markerLongitude)
    annotation.coordinate = location
    annotation.subtitle = "Subtitle"
    mapView.addAnnotation(annotation)
 }
}

您可以打开URL以在特定点/地址打开地图应用程序:


但我不认为,您可以在地图应用程序中设计自定义标记

您可以打开URL以在特定点/地址打开地图应用程序:

但是我不认为,你可以在地图应用程序中设计一个自定义标记