ios - 在 iOS map 中显示多个注释

标签 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,经度:long,标题:“苹果总部”,副标题:“欢迎来到苹果”)

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 将同时在图表上添加多个用户。

最佳答案

这就是我实现它的方法

已添加

          self.mapView.showsUserLocation = true

里面

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

关于ios - 在 iOS map 中显示多个注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37943364/

相关文章:

ios - 如何在 IOS Apps Swift 中处理强制关闭

ios - 导航到 MKMapView 上的注释位置

mapkit - 为缓存的图 block 自定义 MKTileOverlay

iOS 框架版本不会改变

ios - Flutter 应用程序卡在设备的初始屏幕上

ios - 如何在 Theos 中向 UIStatusBar 添加 subview ?

ios - 滚动时表格 View 单元格复选标记会更改位置

ios - Swift 为 View 背景绘制弧线

swift - 在使用 Alamofire 发出获取请求时,除了 `isSuccess` 之外,我还应该使用什么其他成员?

ios - MKMapSnapshotter 渲染边框为白色