2016-08-03 27 views

回答

0

首先,你必須創建一個MKAnnotationView,使用此功能來創建標記:

internal func setupMarker(image:UIImage,long:Double,lat:Double,title:String,subtitle:String) -> MKAnnotationView{ 
    var pinAnnotationView:MKAnnotationView! 
    var pointAnnotation:MKPointAnnotation! 

    pointAnnotation = MKPointAnnotation() 
    pointAnnotation.title = title 
    pointAnnotation.subtitle = subtitle 
    pointAnnotation.coordinate = CLLocationCoordinate2D(latitude:lat, longitude:long) 
    pinAnnotationView = MKPinAnnotationView(annotation: pointAnnotation, reuseIdentifier: nil) 
    pinAnnotationView.image = image 
    pinAnnotationView.canShowCallout = true 

    return pinAnnotationView 
} 

創建標記:

var marker = setupMarker(store.image.image, long: store.location.longitude, lat: store.location.latitude, param: "store",storeId: store.description)) 

標記添加到您的MapView

mapView.addAnnotation(marker.annotation!) 
相關問題