From the course: Code Clinic: Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Show geolocation on a map - Swift Tutorial
From the course: Code Clinic: Swift
Show geolocation on a map
- [Narrator] So we're reading that IP address information but we're not yet displaying it on the map, so let's look at centering our map on the location of the IP address. So we'll stop the app and return to Xcode and I'm going to scroll down to the bottom of do block here, create a few new lines, and then I'm going to start by getting the latitude and longitude. If we look at our data object in our data file, you'll see that latitude and longitude are actually stored within this location and property. They're separated by a comma. We're going to need to separate those and we'll do that ViewController.swift. We'll type Let coordinates = data.loc.sp and that get us an array of substrings and the separator is going to be a comma character. Then on the next line, we're going to create our latitude object. Let lat:CLLocationDegrees. Make sure you've imported core locations or else this won't work. Right there, import core location and we'll set this equal to. We'll call this…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.