在iOS Map中显示几个注释

时间:2016-06-21 11:37:02

标签: ios swift mapkit

我正在尝试向用户显示该区域附近的当前位置和用户。

我正在向用户展示

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location  = locations.last
    let center = CLLocationCoordinate2D(latitude:location!.coordinate.latitude ,longitude :  location!.coordinate.longitude )
    let span = MKCoordinateSpanMake(0.01,0.01 )

    let region = MKCoordinateRegion(center: center, span: span)
    self.mapView.setRegion(region, animated: true)
    self.manager.stopUpdatingLocation()
}

用户附近绘图 plotUsersonGraph(lat,longitude:long,title:"Apple HQ",subtitle:"Welcome to Apple")

func plotUsersonGraph(latitude:Double,longitude:Double,title:String,subtitle:String){
        let HQlocation = CLLocationCoordinate2DMake(latitude, longitude)
        let span = MKCoordinateSpanMake(0.01, 0.01)
        let region = MKCoordinateRegion(center: HQlocation, span: span)
      //  self.mapView.setRegion(region, animated: true)**THIS IS CAUSING PROBLEM**

        let annotation = MKPointAnnotation()
        annotation.coordinate = HQlocation

        annotation.title = title
        annotation.subtitle = subtitle
        self.mapView.addAnnotation(annotation)

    }

我可以单独查看这两个位置,但我无法将它们合并在一起。 plotUsersonGraph会同时在图表上添加多个用户。

1 个答案:

答案 0 :(得分:0)

这就是我实现它的方式

已添加

          self.mapView.showsUserLocation = true

里面

    func plotUsersonGraph(latitude:Double,longitude:Double,title:String,subtitle:String){
}