我想用swift在我的项目中添加一个注释点。但我没有在我的模拟器上添加

时间:2016-05-15 16:32:26

标签: ios swift mkmapview

每当位置更新时我都会添加注释,但它不适用于模拟器。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location = locations.last
    print("my Current location is \(location?.coordinate.latitude) ")
    let center = CLLocationCoordinate2D(latitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

    self.mapView.setRegion(region, animated: true)

    let myCurrentLocation = MKPointAnnotation()
    myCurrentLocation.coordinate=center
    myCurrentLocation.title = "Where I am"
    myCurrentLocation.subtitle = "Here I am"

    self.mapView .addAnnotation(myCurrentLocation)
}

0 个答案:

没有答案