Skip to main content

Set multiple pins on MapKit view swift 3

//Using lat-long array we can eaisly set multiple pin over map.

let locations = [
    ["title": "New York, NY",    "latitude": 40.713054, "longitude": -74.007228],
    ["title": "Los Angeles, CA", "latitude": 34.052238, "longitude": -118.243344],
    ["title": "Chicago, IL",     "latitude": 41.883229, "longitude": -87.632398]
]

for location in locations {
    let annotation = MKPointAnnotation()
    annotation.title = location["title"] as? String
    annotation.coordinate = CLLocationCoordinate2D(latitude: location["latitude"] as! Double, longitude: location["longitude"] as! Double)
    mapView.addAnnotation(annotation)
}
Happy Coding :)

Comments

Popular posts from this blog

post method using alamofire in swift 3

  func addSubscriptionApi(_completeUrl: String ) {         //HUD         Alamofire.request(_completeUrl, method:.post, parameters: nil , encoding: JSONEncoding. default , headers: nil ).responseJSON { response in             switch (response.result) {             case .success( _ ):                 if let data = response.result.value as ? NSDictionary                 {                     print(response.result.value as Any)                     print(data)                      print("SUCCESS")                  }                 break  ...

Set Placeholder in UiTextView in swift 3

//In viewdidLoad add this                DiscriptionTV . text = "Discription"         DiscriptionTV . textColor = UIColor . lightGray         DiscriptionTV . delegate = self          DiscriptionTV . layer . borderColor = UIColor . lightGray . cgColor ; then   //Mark:- textView Delegates          func textViewDidBeginEditing( _ textView: UITextView ) {         if DiscriptionTV . textColor == UIColor . lightGray {             DiscriptionTV . text = nil             DiscriptionTV . textColor = UIColor . white             DiscriptionLab . isHidden = false         }     }          func textViewDidEndEditing( _ textView: UITextView ) { ...