Blog

Your First Project With LocationKit (Video Tutorial)

September 11, 2015

This entry was posted in iOS, LocationKit tagged

Gathering rich location-based information on your users is just just a few simple steps away. Our VP of Engineering, Victor Quinn, walks us through the ease of a LocationKit integration. Check out the video below and begin to harness the most advanced location SDK.

 

Video Transcript 

Welcome to your first project that LocationKit. In this video we’re gonna show you how to start LocationKit,  how to get a single location point and how to get info about the current place. If you haven’t already make sure you watch our Getting Started video that will show you how to get the project all set up. If you followed along with our last video you should have your project all configured and ready to go for LocationKit. So let’s jump in the code here let’s go to the app delegate let’s remove all these methods we don’t really care about. You’re gonna make sure to leave did-finish launching with options because that’s where we’re going to actually start locationkit. Now the next thing we need is our API token now this unique to every developer and you can get to get it off the developer dashboard. It’s at dashboard.locationkit.io. If you haven’t already just pop in here sign up for an account and will load into the dashboard. Now the piece we want right now is the API token so it’s gonna tokens and let’s copy this API token to the clipboard. Of course like I said before this is unique to each developer to identify your application. So starting LocationKit is really easy just one line of code. We’re gonna do locationkit . shared instance . start with API token. And notices how it all auto completes very easy. Plop in the token and for now we’re going to provide a nill delegate. I’ll explain more what that means later but for now just leave it is nill. And we’re going to launch it and you’ll notice that it compiles it builds, we’ve got no problems and if I drag it over here notice we got the pop up that says allow us to access your location, that’s a good thing that means we had everything configured correctly in the previous steps. and now we’re running now when I do much let’s make it actually do something cool. 

To show you how easy it is to level up your location with locationkit we’re gonna start with something really basic getting a single location point as a latitude and longitude. So let’s jump into the storyboard here and first what we’re gonna do is make a button so we’re gonna make a simple button that just says where am i and when you tap that but we’re going to use Locationkit to get the user’s current location and we’re gonna just log it for now ok. So let’s first drag a button to this container here and I’m gonna call it “Where Am I?” Now when the user click this button I’m gonna use locationkit to show them where they are. First let’s center this button here, we’re certainly not going to win any awards for our amazing UI design but it’ll mostly kinda stick to the center of the screen which is good. And the next thing we’re going to do is we’re going to stitch it up to our view controllers so that we can actually get an action called when this button is tapped. So we’re going to control dragged into our view controller here, we’re going to make sure it’s an action not an outlet so that we get that call back when the button is tapped, we’re gonna change it to type UI button from any object and let’s just call it “where am I?” straightforward simple to the point. now whenever our Design Award winning where am i but has tapped this code is going to execute and what we’re gonna do is just use locationkit to get the user’s current location and again it’s going to be very rudimentary now we’re just gonna get a latitude longitude just gonna get us get us started and then we’ll get into more complex stuff. so in order to get the user’s current lat/long, it’s very easy with LocationKit. We’re going to do locationkit . shared instance now in this case we could continue putting dots after but I’m actually gonna sign it to a variable to make the code a little bit more succinct. Now using our local reference location words gonna run locationkit . getcurrentlocationwithhandler Again at all auto completes its nice and easy. And expects a handler to be supplied which gets to arguments the first one is just a location which is a CL location object if you were to location services will be very familiar to you and the second ones is an error. The first thing we’re going to do within this handler is create an if statement now we’re going to create a local copy of our location we’re going to start in a variable LOC the reasoning behind this again until later. alright so we’re just gonna do a print line statement and we’re just going to print out the location, so if you worked with location services in iOS in the past this should be very comfortable and familiar for you because the location that we actually send in is a CL location object. so that means it has coordinates and those coordinates have a latitude and longitude so this print line statement just gonna print out that latitude longitude and then we’re also going to print a statement in case we get a nilt location now strictly speaking this isn’t a hundred percent necessary the way we’ve got the code written here because the location in this case is not an optional but it’s good practice and it could actually be provided as an optional and I’ll explain more in the text accompanying video and for instance a place where I could be nill as if the user’s revoke permissions for your app to view location then discard that could be called within a location and you’ll notice the location we actually send is a CL location object so if you’ve worked with core location on iOS previously this should be a very familiar to you so we’ve got coordinates we’ve got altitude we’ve got horizontal accuracy core speed its locationkit will actually send these points to you as a CL location objects making it very easy to integrate especially if you’ve already use location services in the past. so we’re going to build and run this year and those that builds and runs very quickly and we’re off. so one thing I’m gonna do right now is go off screen here and go to debug location and I’m gonna pick a particular location you have to do that with the simulator because obviously doesn’t have an actual GPS chip and when I get where we’ve got the current location of the device very very simple you see the lat.long enough to go back to see me later here I can hit where am i again and you gonna know this I’m gonna get another point and again and again each time I press it location is going to provide the device’s location at that point in time so this should show you how really easy it is to get started with location on locationkit can but this is only scratching the surface what we can do let’s go on to something a little bit more complex.

So rather than just showing the lat/long and the device which is pretty boring and useless we’re going to leverage the power locationkit show contextual information on the place where the device is. so we’re gonna go ahead and get rid of this whole get current location with handler chunk and we’re going to replace it with the far more useful locationkit . getcurrentplacewith handler with this gonna do is can actually figure out the current location of the device it’s going to go talk to our servers and its gonna send on all the information we have in our backend database about that place I’ll go into more detail about that in second so for now we want to handler thats going to receive an optional place and an optional error as well so of course for swift we need to make sure that this exists and is not nill first so we’re going to do if let’s play singles place in the block here we’re going to print out the error if there was some reason some error fetching the place could be for instance there’s no network connection for the phone at the given point in time lets users in the basement has no cell connection or there’s something else funky going on at the device so in the other time code we’re just going to print out the information that we have in the place so a place again it’s got a bunch of attributes all talk more about that in the second but one of the things that a place as is an address so we can easily bring out the attributes of the outer so we’re gonna bring out the address street number first and then the addresses street name and they’re going to follow that up with the address is locality and region now locality and region are functionally equivalent to america’s city and state but in locationkit we use the county and region to make sure that we have compatibility with internationalization of these addresses and again the place object has a lot more than just the address but we’ll get into that in a second so we’re gonna go ahead and run this year and building and here we are so look the same we got the win but now you could say we’re going to get an actual address see how much useful that is then just getting a latitude and longitude for the place I can look at that and understand that’s the White House and make sense to me as a human being instead of just a computer that speaks lat/longs that’s just a little bit of the power of locationkit and so I’m gonna load up our locs page here its docs.locationkit.io and I’m gonna give a little bit more detail about all the rich information that you get back with that place subject and herein lies the real power of locationkit so if you notice we didn’t have to request a lat long and then say hey where the heck is wrong we just said where is my current place and you get this place which has a venue it has an address it has events and has potentially alternatives and so it’s incredibly rich contextual information that you’re getting with almost no work we had one line of code and that’s a really great illustration of how easy it is with locationkit to get rich location information into your app without having to maintain a location expertise on your own team so getting back to our LK place object a place where almost always have an address so pretty much everywhere has an address it will sometimes have a venue so places like a Starbucks or CVS anyplace you would call a venue will have an address and the venue but a private home won’t have a venue and then if there are any events going on there it’ll have that as well so open mic night or something and then alternatives to the list of other places that are nearby which might be right just in case we tried to pick the right place and didn’t get the one that was quite right for your particular use case and each of these documents detail so for instance of venue has a category and subcategory right so an address has all these attributes about him again we talked about region locality in a few of those things and it’s got more an event has these attributes are start time and time again it’s all in our documentation it’s all rich and we’re here to help so if there is any question about anything that’s going on here feel free to jump into the community and ask us questions and his emails tweet at us find us on our IRC will get back in touch with you.

And that’s it this has been your first project with location can we hope it’s been useful and stay tuned next time we talk about more advanced topics such as using location can’t delegate to get always on background updates on user visits.

TL;DR 

1. How to get started used LocationKit

2. Getting a single lat/long location on users

3. Getting contextual information about the current place

 

Comments

No comments yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">