From the course: Code Clinic: Swift

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Access geolocation

Access geolocation - Swift Tutorial

From the course: Code Clinic: Swift

Start my 1-month free trial

Access geolocation

- [Instructor] Now let's look at using the IP info API to show geolocation data inside of our application. Remember we have this IPData struct with all the properties set up properly. I'll scroll down into the showIPData method, and what we're gonna do in here is we need a URL to grab data from. I'm going to define an object called URL that's of the type URL, and then I'll set it equal to the URL constructor, and I'll use the one that asks for a string and then pass in the URL as a string. So https://ipinfo.io/ the IP address. I'll use the Google IP address, and then /geo. If you're going to be using your access token, add that as a parameter. So ?token=, and then the value of my token constant right there, and I'll unwrap that. I'm going to put a comment above this. Put google's ip, and let's just copy this a few times, and change the code in case you want to look up your own IP or use the file that we've saved the JSON data to. Copy this. Paste it. Change Google's IP to your IP, and…

Contents