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 >>
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 look up a location with MKLocalSearch.Request
MapKit has built-in functionality to let us look up places and businesses around the world, all using natural language searches that can be passed in straight from user entry.... 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 >>
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions, all written for Swift.
Link copied to your pasteboard.