New to Swift/SwiftUI, but currently developing an app with SwiftUI and have reached a stopping point because I cannot figure out for the life of me how to simply get the user's current location when they tap a button. SURELY this cannot be this hard?! Any help would be greatly appreciated!
All I'm after really is to get the user ultimately be able to drop a pin on a map (using MapKit
) at their current location when they tap a button.
Using the CLLocationManager, you can call the requestLocation
() method... You can use an @IBAction for when the button is pressed, and just call the requestLocation()
method inside this IBAction! I hope this helped!
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.