Map View - Current Location in Swift - Xcode 7 iOS 9 Tutorial

Map View - Current Location in Swift - Xcode 7 iOS 9 Tutorial


In this tutorial we learn how to display the users current location on a map view.​

Sponsor: Get the iOS 9 Developer Course with Swift 2 and Xcode 7!

http://bit.ly/1Mrsifz

Source Code:

http://bit.ly/22GmWoa

To Subscribe To Vea Software Weekly:

http://www.veasoftware.com/newsletter

To Support Vea Software:

http://www.veasoftware.com/donate

Social Accounts:

Twitter: https://twitter.com/veasoftware

GitHub: https://github.com/veasoftware

Facebook: https://www.facebook.com/veasoftware

Instagram: https://instagram.com/theveasoftware/

Pinterest: https://www.pinterest.com/veasoftware/

Please leave feedback on how I can improve my tutorials and suggest what tutorials I can do next! :D
Closed Caption:

hello and welcome to a via software
tutorial i'm your host pj via and i'm
the founder of via software before we
get started I'd like to think this video
sponsor iOS dev course be the first to
get iOS 9 and Swift to developer course
for just nineteen dollars today
learn how to build a flappy bird and
whatsapp clone this is an incredible
bargain and I'll be telling you more
about it at the end of the video
alright so today we're going to be
learning how to use a map view to
display the users current location
so to show you what we will be building
today i have it running right here in
the simulator and i'm going to open up
and as you can see we just have a map
view it's going to zoom in to my current
location and display the little blue dot
which signifies that is my current
location and if you're wondering i'm not
actually in California
it's just i'm using the debug location
Apple so this is actually a police
headquarters that is showing for my
current location
but anyways let's jump in Xcode and get
started so I'm hoping an opening up
xcode seven and i'm going to create a
new Xcode project and this will be a
single View application and click Next
and for the product name
I'm just going to call it map view and
for language make sure it's set to Swift
and then click Next and i'm just going
to let me live on the desktop
ok so the first thing we need to do is
set up our user interface lets go into
our main story board and i'm just going
to lower part of my screen so I can see
everything ok
and i'm going to select the view
controller and i'm going to add a
navigation controller
this isn't really necessary for the
tutorial but i just think it looks
better so I'm going to go out to editor
embed in navigation controller and now
our view controller is embedded inside
of a navigation controller and i'm just
going to set its title to current
location and then I'm going to grab a
map view from the object library and
drag it onto our view controller and i'm
going to make it go
the entire width and height of our view
controller oops
and then I'm going to go to the auto
layout constraints of the auto layout
tool and say add missing constraints and
that will add our missing constraints
for our map view
so what the map view is still selected
open up the assistant editor and control
drag from the map view to our view
controller that way we can link our user
interface to our code with an outlet and
i'm just going to call it a map view and
then connect and that's actually all we
need for our storyboard
so i'm going to close the assistant
editor go back into the Standard editor
and then go into our view controller .
Swift
so before we actually do anything in
here
let's actually go into work info . p
list and add that necessary
location when in usage description
because if you don't have that none of
the location services are going to work
and this is saying this is giving giving
us an error and I'll fix that here in a
second
so let's go into our info . p list and
we're just going to add plus and start
typing NS location when in use
usage description
ok and we can set the strange whatever
you want like app needs location
services for stuff probably need a
better one for your app but that works
fine for us so it's going to our
viewcontroller Swift and I'll explain
why this is giving us this area and this
is because it doesn't know what an MK
map view is so we need to actually
import the map kit frameworks are going
to import map pack it and that will fix
that and we're also going to need the
core location services that way we can
get the users current locations we're
going to take or location
ok so now we are going to create a
location manager property
so we're going to say let location
manager equals CL location manager
there you go and insert our view did
load we're going to set up our location
manager that way it can start finding
the current location as soon as the view
is loaded
so we say self dot location manager .
delegate equals self and speaking of
delegate
let's actually make our viewcontroller
conform to the protocol since I forgot
to do that at the beginning so we first
needed to conform to the MK map view
delegate and the CL location manager
delegate there you ok so now we're going
to say self dot location manager .
desired accuracy equals k CL location
accuracy best self . location manager .
request when in use
authorization self . location manager .
start updating location
are you okay so just to explain this
this conforms it to the delegate method
that's pretty straight for it
desired location we're setting it to
accuracy best because we want the users
exact location so we want the accuracy
to be the best as possible
we want the request when in use
authorization and the reason we want
this is because we only want to be using
location services when we're using the
app
we don't want to use location services
when the app is in the background and
then we're going to start looking for
the location so this is going to
actually turn on the location manager to
go look for a location
so now we need to implement the location
manager delegate methods and let me add
some white space here
ok so this is going to be for the
location
delegate methods ok so location manager
did update locations
that's the first one we're going to say
let location equals locations . last
so that is this location here that's
being passed in so since this did update
location is being called over and over
and over again after you call the start
updating location
it's going to continually call this
method until we tell it to stock so
that's why we're saying location that
last because we want the most current
one and then we're going to say let
center equal CL location coordinate
location coordinate 2d Mario latitude
location . coordinate . latitude
location . coordinate
. longitude let's region equal
mkay coordinate mkay
yeah coordinate region
Center center span
mkay coordinate span one and one and
i'll explain all this here in a second
self dot map view . set region region
animated true self . location manager .
stop updating location
ok so like I explained up here we're
getting the last location from our
locations that are being passed in and
then we're getting the center of that
location
so that's why we're getting the latitude
and longitude out of the location
variable and then we're creating a
region
so this is going to be basically a
circle that we're going to we want the
map to zoom - and that's what this MK
coordinate span is this one and one that
is the actual zoom so if you set that to
say five it's going to zoom way out and
so the smaller the number the farther in
is zooms in and then we set that map
view to the region because we wanted to
you know we want the map view to go to
that region and zoom in and and so this
latitude longitude is actually the users
current location so we're zooming into
the users current location and we set
the animated - yes that way you get that
little like zooming animation and since
we have the users current location and
the map you zoomed in
we can stop updating the location so
let's actually set up for the air is
just case we get an error so we want to
say print
I'll just say errors plus error .
localized description
so just print out an error to the
debugger if we have one with the
location manager
so there's one more thing that we have
left to do and that is right now we will
have the users current location and it
will zoom into the correct location with
that span of one and one but it will not
show that blue . yet
so what you actually have to do is up
here in the view did load going to say
self dot map view . show user location
show shows user locations with this
equals self
r equals true are you okay so now we can
build and run this and everything should
be working
ok so it asks us for current location
we're going to say allow and now it's
going to zoom in to our current location
and display the little blue dot that
sends a little radius and you can zoom
in
if you would like if you're wondering
how i'm doing that you can just hold
down the option key and then click and
drag and i will zoom in and there we are
in cupertino
and oh there's the apple logo because
we're at the Apple headquarters
so anyways I hope that was helpful
before I let you go though I want to
tell you a little bit more from our
sponsor
so this video is sponsored by iOS def
course be the first to get iOS 9 and
Swift to developer course for just
nineteen dollars today with this course
you'll get lifetime access to over 20
hours of fun practical video lessons
explaining from scratch
how to make great and highly functional
apps for iOS 9 with xcode seven a
collection of over 1,000 icons graphic
assets worth two hundred dollars to make
your absolute great and professional an
ebook on how to make ten thousand
dollars as an app developer a theme with
fifty dollars for building your website
to market your apps full one-on-one
support with instructors build your iOS
apps on your own pcs build flappy bird
and whatsapp clones and you can get
access to a one hundred and ninety nine
dollar course for just nineteen dollars
plus you can support other levels at
different price points and receive
rewards such as 1100 extra icons and
another gives you access to this course
and another course there is a reward of
an early access to go get iOS 9 course
before anyone else heck one level even
gives you access to everything the
authors putting out and now putting out
now and in the future as well as full
one-on-one support with the author
himself
there's a link to it in the description
down below so go check it out and help
make great iOS 9 and swift - with xcode
seven-course for yourself and others
well that's everything ahead for this
week i hope you enjoyed the video if you
did please give it a thumbs up and if
you want to see more videos like this
please hit subscribe and as always don't
forget to check out via SoftWIRE . com

Video Length: 11:49
Uploaded By: Vea Software
View Count: 44,585

Related Software Products
Map View SDK
Map View SDK

Published By:
Offlinesoft

Description:
The Map View SDK is available as a stand alone Developer kit. The Map View SDK offers a Direct DLL method to draw multi-type maps by region within your application. The satellite maps and the street maps will be easily used as background maps within your application such as GIS. The Map View SDK is not a Royalty Free tool kit and a limited number of Licenses are included for end user distribution with your application with the SDK product you purchase, with additional bulk license packs ...


Related Videos
Swift: How to integrate Google Maps SDK with Cocoapods to Build a Vacation App
Swift: How to integrate Google Maps SDK with Cocoapods to Build a Vacation App

Today, we'll go over step by step how to integrate Google Maps SDK for iOS using Swift and Cocoapods to build a Vacation App. We'll go over how to set the map view centered on the interesting places of San Francisco, CA. In addition, we'll place markers on these spots. Next, we take a look at how to animate the camera from one location to then next. Finally, when we are completely done, we'll have created a flyover application that explores some of my favorite spots the city has ...
Video Length: 26:17
Uploaded By: Lets Build That App
View Count: 20,944

XCode 5 Tutorial Map View Part 1 - Displaying Map Views - Geeky Lemon Development
XCode 5 Tutorial Map View Part 1 - Displaying Map Views - Geeky Lemon Development

Free Crash Course: http://www.iosdevelopmentcrashcourse.com Source Code: http://www.geekylemon.com/#!map-views... Hey guys in this tutorial i will be showing you how to make a map view with advance feature to locate your location and change between hybrid satellite and map views i hope this help you out in your projects and if there anyway you think i can improve my tutorials or want to request one just tell me via comment or pm and subscribe please leave feedback on ...
Video Length: 10:42
Uploaded By: GeekyLemon
View Count: 19,049

Maps Live: Google Maps SDK for iOS Version 1.4
Maps Live: Google Maps SDK for iOS Version 1.4

The latest version of the Google Maps SDK for iOS, version 1.4, comes with great new features such as Street View, Indoor Maps, and a new look and feel. Mano Marks and Luke Mahe from the Google Maps Developer Relations Team demo these features for you and talk about how you can add them to your application. hr / bClosed Caption:/b MANO MARKS: Hi, I'm Mano Marks. LUKE MAHE: And I'm Luke Mahe. MANO MARKS: We're on the Google Maps ...
Video Length: 01:59
Uploaded By: Google Developers
View Count: 13,901

Map Padding with the Google Maps SDK for iOS
Map Padding with the Google Maps SDK for iOS

Map padding in the Google Maps SDK for iOS (http://goo.gl/8n3lV) allows you to change the visible region of your map, so that your controls, logo, and copyright notices are all aligned with your view. In this video, Mano Marks explores the benefits of map padding and how to implement it in the SDK. hr / bClosed Caption:/b Hi, I'm Mano Marks. I'm a developer advocate on the Google Maps team. In this video, I'm going to show you how ...
Video Length: 02:16
Uploaded By: Google Developers
View Count: 11,359

Maps Shortcuts: Indoor Maps in the Google Maps SDK for iOS
Maps Shortcuts: Indoor Maps in the Google Maps SDK for iOS

Mano Marks shows you how use the Google Maps SDK for iOS (http://goo.gl/8n3lV) to create a map that has indoor floor plans and how to create a custom level picker in your app. hr / bClosed Caption:/b Hi, I'm Mano Marks. I'm developer advocate on the Google Maps Developer Relations team. I want to welcome you to this week's Google Maps shortcut. In this episode, we'll be talking about the Google Maps SDK for iOS ...
Video Length: 08:16
Uploaded By: Google Developers
View Count: 9,853

2D/3D Indoor Map SDK for iOS and Android
2D/3D Indoor Map SDK for iOS and Android

This video shows the indoor map SDK by Heidelberg Mobil International GmbH. The Deep Map™ SDK gives you a nice view of an area with different buildings. You can pitch, zoom and click the 2D/3D multifloor map. Routing from one room to another can be shown on the map. Zoom into floor level to see more details from the building. The 2D/3D map can be used for iOS and Android devices. An also interactive 2D map can be used for websites. Find out more at: www.deep-map.com
Video Length: 01:30
Uploaded By: Heidelberg Mobil
View Count: 9,028

iPhone SDK Tutorial Part 1 TabBarController showing WebView and MapView
iPhone SDK Tutorial Part 1 TabBarController showing WebView and MapView

Here we develop an application presenting multiple views using using a tab bar controller. The tab bars presents a web view and a map view. We also add icons to the tab bar items. You can download the source code for the app here: http://cloud.github.com/downloads/car... hr / bClosed Caption:/b well hello I the system with burkhart is a bit and this is my first tutorial on your iPhone SDK development and the topic recovering ...
Video Length: 09:35
Uploaded By: carticipate
View Count: 9,008

iPhone SDK Tutorial   Part 4 TabBarController showing WebView and MapView
iPhone SDK Tutorial Part 4 TabBarController showing WebView and MapView

Here we develop an application presenting multiple views using using a tab bar controller. The tab bars presents a web view and a map view. We also add icons to the tab bar items. The video is a lengthy, and goes into more depth with explanation of what the code does. Not just a how to, but also a how so. You can download the source code for the app here: http://cloud.github.com/downloads/car... hr / bClosed Caption:/b okay so we're gonna call ...
Video Length: 07:59
Uploaded By: carticipate
View Count: 7,247

Copyright © 2025, Ivertech. All rights reserved.