FREE: Read a new Swift article every day – click here! >>

Location

Found 9 articles in the Swift Knowledge Base for this category:

 

Adding places to MKMapView using MKPlacemark

You can add places to any map view using the MKPlacemark class, and it’s different from adding regular annotations – the map view shows the whole address on the map, even from far away, so users can see important points easily.... Continue Reading >>

How to add a button to an MKMapView annotation

The built-in MKPinAnnotationView annotation view has a rightCalloutAccessoryView property that can be set to any kind of UIView, including buttons. The button doesn't need to have an action attached to it, because there's a separate method that gets called when it's tapped.... Continue Reading >>

How to add an MKMapView using MapKit

Map views are pretty easy in iOS, largely because they are baked right into Interface Builder. That's right: open your storyboard, drag a map view into your view, and you're already most of the way there!... Continue Reading >>

How to add annotations to MKMapView using MKPointAnnotation and MKPinAnnotationView

Once you have an MKMapView up and running, it only takes a few lines of code more to drop pins containing placemarks.... Continue Reading >>

How to detect iBeacons

Detecting iBeacons requires a number of steps, but before we can start writing any code we first need to add some privacy descriptions to your Info.plist file. These are shown to users when you request location access, and it’s your chance to explain to users why you need location access.... Continue Reading >>

How to find directions using MKMapView and MKDirections.Request

MapKit is great for letting users navigate from place to place, but also makes it easy for you to plot directions from one place to another. You just tell iOS where you're starting from, where you're going, as well as how you're traveling (by car, foot, or mass transit), and it will find routes for you.... Continue Reading >>

How to make an iPhone transmit an iBeacon

iOS 7.0 introduced not only the ability to detect iBeacons, but also the ability to create iBeacons – for iPhones and iPads to broadcast their own beacon signal that can then be detected by other devices. To make this work, you add these two imports:... Continue Reading >>

How to read the user’s location while your app is in the background

iOS has had the ability to track locations in the background for some time, but the permission system changed in iOS 8 then again in iOS 11 as Apple has tried to stop unscrupulous apps abusing private information.... Continue Reading >>

How to request a user's location only once using requestLocation

iOS has a simple way to request a user's location just once, and it's called requestLocation(). Calling this method returns immediately (meaning that your code carries on executing) but when iOS has managed (or failed) to get a fix on the user's location you will be told. Below is a complete example:... Continue Reading >>

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions, all written for Swift 4.2.

Build for watchOS

Take your existing Swift skills to Apple's tiniest platform – check out Hacking with watchOS!

MASTER SWIFT NOW
Buy Testing Swift Buy Practical iOS 12 Buy Pro Swift Buy Swift Design Patterns Buy Swift Coding Challenges Buy Server-Side Swift (Vapor Edition) Buy Server-Side Swift (Kitura Edition) Buy Hacking with macOS Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with Swift Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let me know!

Click here to visit the Hacking with Swift store >>