简体   繁体   中英

Show several annotations in iOS Map

I am trying to show user's current location and users nearby the area.

I am doing to show user's

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()
}

Plotting near by users 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)

    }

I am able to view both the locations individually but I am unable to merge both of them together. plotUsersonGraph will add multiple users on the graph simultaneously.

This is how I achieved it

Added

          self.mapView.showsUserLocation = true

inside

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM