Post

Replies

Boosts

Views

Activity

Reply to How do I display a value in a label (the value keeps changing/updating)
@claude31 I feel like the problem is not knowing where I should insert your code, so here is my entire code, and you determine which line I should put your code at (this is in the viewController btw): import MapKit import UIKit import CoreLocation import UserNotifications class ViewController: UIViewController, CLLocationManagerDelegate {     @IBOutlet var mapView: MKMapView!     let manager = CLLocationManager()     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     }     override func viewDidAppear(_ animated: Bool) {         super.viewDidAppear(animated)         manager.desiredAccuracy = kCLLocationAccuracyBest         manager.delegate = self         manager.requestWhenInUseAuthorization()         manager.startUpdatingLocation()     }     func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {         if let location = locations.first{             manager.stopUpdatingLocation()             render(location)         }         func render(_ location: CLLocation){             let coordinate = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)             let span = MKCoordinateSpan (latitudeDelta: 0.1, longitudeDelta: 0.1)             let region = MKCoordinateRegion(center: coordinate, span: span)             mapView.setRegion(region, animated: true)             mapView.showsUserLocation = true             let pin = MKPointAnnotation()             pin.coordinate = coordinate             pin.title = "your home"             pin.subtitle = "Location"             mapView.addAnnotation(pin)             func userDistance(from point: MKPointAnnotation) -> Double? {                 guard let userLocation = mapView.userLocation.location else {                     return nil // User location unknown!                 }                 let pointLocation = CLLocation(                     latitude:  point.coordinate.latitude,                     longitude: point.coordinate.longitude                 )                 //hello                                  var value = userLocation.distance(from: pointLocation)                 return value             }         }     }     @IBAction func Button(_ sender: UIButton) {         UIApplication.shared.open(URL(string: "https://www.gps-coordinates.net")! as URL, options: [:], completionHandler: nil)     } }
Jun ’21