Advice - Swift - User Check-in inside MK-circle


I’m learning swift now, so this is my first question here :smiley: I’m creating the app with some annotations on the map. I’ve added MKCircles in radius 200m from the annotation. This should be a radius in which user can check-in and save his loacation. Can I use distance(from:)to do it?

In general I’m looking for some tips/advices how to set this check in (Could be check-in button inside the annotation view) that saves user location if user is in radius 200m from the annotation. The check-in should be connected to the name and describtion of the annotation ( and szczyt.opis), and the annotation name should be saved in a table view “Zdobyte Szczyty”, which is another tab bar view in the app. My mainstoryboard looks like this:

There is a Map controller and Zdobyte Szczyty controller. so I would like to save location only if in radius 200m from annotation as annotation name ( and describtion (szczyt.opis) in table view, which is based in Zdobyte Szczyty viewcontroller.
Here is my map viewcontroller.swift:

import UIKit
import MapKit

class ViewController: UIViewController, MKMapViewDelegate{

 let locationManager = CLLocationManager()

struct Szczyt {

  let name: String
  let opis: String
  let lattitude: CLLocationDegrees
  let longtitude: CLLocationDegrees

    var coordinate: CLLocationCoordinate2D {

        .init(latitude: lattitude, longitude: longtitude)


@IBOutlet weak var mapView: MKMapView!

@IBAction func mapTypeSegmentSelected(_ sender: UISegmentedControl) {

        switch sender.selectedSegmentIndex {

        case 0:

            mapView.mapType = .standard

        case 1:

            mapView.mapType = .satellite


            mapView.mapType = .hybrid


private(set) var circles: [MKCircle]!

let szczyty = [Szczyt(name: “one”, opis: “describtion”, lattitude: 50.825061725039226, longtitude: 16.908595782487315),

               Szczyt(name: “two, opis: “describtion”, lattitude: 50.223874478583854, longtitude: 20.996341184611302),

               Szczyt(name: “three”, opis: “describtion”, lattitude: 50.756134079897516, longtitude: 15.984675411850157)]

override func viewDidLoad() {




    circles = {

           MKCircle(center: $0.coordinate, radius: 200)


    mapView.delegate = self
    func checkLocationServices() {

      if CLLocationManager.locationServicesEnabled() {


      } else {

        // Show alert letting the user know they have to turn this on.      

    func checkLocationAuthorization() {

      switch CLLocationManager.authorizationStatus() {

      case .authorizedWhenInUse:

        mapView.showsUserLocation = true

       case .denied: // Show alert telling users how to turn on permissions


      case .notDetermined:


        mapView.showsUserLocation = true

      case .restricted: // Show an alert letting them know what’s up


      case .authorizedAlways:


func znajdzSzczytyNaMapie(_ szczyty: [Szczyt]) {

  for szczyt in szczyty {

    let annotations = MKPointAnnotation()

    annotations.title =

    annotations.subtitle = szczyt.opis

    annotations.coordinate = CLLocationCoordinate2D(latitude:

      szczyt.lattitude, longitude: szczyt.longtitude)


 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    guard !(annotation is MKUserLocation) else { return nil }

    let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")

    switch annotation.title!! {

        case “one”:

            annotationView.markerTintColor = UIColor(red: 0.86, green: 0.99, blue: 0.79, alpha: 1.00)

            annotationView.glyphImage = UIImage(named: "bald")

        case “two”:

            annotationView.markerTintColor = UIColor(red: 0.80, green: 0.98, blue: 0.73, alpha: 1.00)

            annotationView.glyphImage = UIImage(named: "bear")

        case “three”:

            annotationView.markerTintColor = UIColor(red: 0.73, green: 0.98, blue: 0.68, alpha: 1.00)

            annotationView.glyphImage = UIImage(named: "spruces")

    return annotationView

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {

    let circleRenderer = MKCircleRenderer(overlay: overlay)

    circleRenderer.strokeColor =

    circleRenderer.fillColor =

    circleRenderer.alpha = 0.3

    circleRenderer.lineWidth = 1.0

    return circleRenderer

Here is my ZdobyteSzczyty view controller:

import UIKit

class Zdobyte_ViewController: UIViewController {
    override func viewDidLoad() { 


This topic was automatically closed after 166 days. New replies are no longer allowed.