1

我正在尝试添加一个标记目的地的 MKPointAnnotation。那destinationMKMapItem从前一个视图控制器传递的。我知道destination有一个值,因为CLCircularRegion它的右下方使用destination为中心并在用户在范围内时触发。我添加注释的方式有什么问题吗?

import UIKit
import MapKit
import CoreLocation

class ViewController2: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate{

var map: MKMapView?
var manager: CLLocationManager?
var destination: MKMapItem?


convenience init(frame:CGRect, destination:MKMapItem){
    self.init(nibName: nil, bundle: nil)
    self.destination = destination
    self.view.frame = frame


    self.map = MKMapView(frame: frame)
    self.map!.delegate = self

    self.view.addSubview(self.map!)
}


func viewDidAppear(animated: Bool) {

        var annotation = MKPointAnnotation()
        annotation.coordinate = destination!.placemark.coordinate
        self.map!.addAnnotation(annotation)

        var center: CLLocationCoordinate2D = destination!.placemark.coordinate
        var radius: CLLocationDistance = CLLocationDistance(300)
        var identifier: String = "Destination"
        let region = CLCircularRegion(center: center, radius: radius, identifier: identifier)
        manager?.startMonitoringForRegion(region)

    }

provideDirections当按下按钮时调用该函数。

import UIKit
import MapKit
import Parse

class ViewController1: UIViewController {

var alat = ""
var alng = ""


func provideDirections(){

                self.manager = CLLocationManager()
                self.manager.startUpdatingLocation()
                println("Location Updated")

                let request = MKDirectionsRequest()
                request.setSource(MKMapItem.mapItemForCurrentLocation())

                let latitude = (alat as NSString).doubleValue
                let longitude = (alng as NSString).doubleValue

                let destinationCoordinate = MKPlacemark(coordinate: CLLocationCoordinate2DMake(latitude, longitude), addressDictionary: nil)

                var secondVC = ViewController2(frame: self.view.frame, destination: MKMapItem(placemark: destinationCoordinate))


                self.navigationController?.pushViewController(secondVC, animated: true)
4

1 回答 1

0

我通过将注释从移动viewDidAppearconvenience init

于 2015-06-17T17:41:14.017 回答