SlideShare a Scribd company logo
1 of 36
Download to read offline
Core Location in iOS
Juan Catalan
jcatalan007@gmail.com
Apps using
location based information
• Using location-based
information in your app is a
great way to keep the user
connected to the surrounding
world. Whether you use this
information for practical
purposes (such as navigation)
or for entertainment, location-
based information can
enhance the overall user
experience.
Location based information
• Location based information consists of two pieces:
location services and maps
• Location services are provided by the Core Location
framework, which defines interfaces for obtaining
information about the user’s location and heading
(the direction in which a device is pointing).
• Maps are provided by the Map Kit framework, which
supports both the display and annotation of maps
similar to those found in the Maps app.
How the iPhone
determines your location
• The iPhone uses a Hybrid Positioning System to
determine your location.
• This system uses a combination of GPS, a crowd-
sourced location database of nearby Wi-Fi
hotspots and the cellular triangulation technique
that determines your rough location based on cell
tower signal strength.
How the iPhone
determines your location
How to get
the user’s location
• Standard Location Service
✴ highly configurable way to get the current location and track
changes
• Significant-change Location Service
✴ get the current location and be notified when significant
changes occur (> 500 m)
• Region monitoring (aka geofences)
✴ boundary crossings for defined geographical regions and
Bluetooth low-energy beacon regions
How to get
the user’s location
• CLLocationManager
• CLLocationManagerDelegate
var locationManager: CLLocationManager?
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.startUpdatingLocation()
locationManager?.startMonitoringSignificantLocationChanges()
func locationManager(manager: CLLocationManager, didUpdateLocations
locations: [CLLocation])
func locationManager(manager: CLLocationManager, didFailWithError error:
NSError)
func locationManager(manager: CLLocationManager,
didChangeAuthorizationStatus status: CLAuthorizationStatus)
Location services
permissions
• When In Use Authorization
✴ Used when the app is in the foreground or
suspended
• Always Authorization
✴ Used always
✴ Launches the app for region monitoring or
significant location changes
Location services
permissions
• When In Use Authorization
var locationManager: CLLocationManager?
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.requestWhenInUseAuthorization()
Location services
permissions
• Always Authorization
var locationManager: CLLocationManager?
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.requestAlwaysAuthorization()
Getting location information
in the background
• Enable capability
• Enable property in CLLocationManager (iOS 9+)
locationManager?.allowsBackgroundLocationUpdates = true
Getting location information
in the background
• When do we need to enable background location
updates in the app capabilities?
Getting location information
in the background
• Check if the user has not disabled background
app refresh globally or for the app
switch UIApplication.sharedApplication().backgroundRefreshStatus {
case .Available:
print("Background updates are available for the app.")
case .Denied:
print("The user explicitly disabled background behavior for this app or for the
whole system.”)
case .Restricted:
print("Background updates are unavailable and the user cannot enable them again.
For example, this status can occur when parental controls are in effect for the
current user.")
}
App launched
by location events
• When an app is relaunched because of a location update, the
launch options dictionary passed to your
application:willFinishLaunchingWithOptions: or
application:didFinishLaunchingWithOptions: method contains
the UIApplicationLaunchOptionsLocationKey key.
• The presence of that key signals that new location data is
waiting to be delivered to your app.
• To obtain that data, you must create a new CLLocationManager
object and restart the location services that you had running
prior to your app’s termination. When you restart those services,
the location manager delivers all pending location updates to its
delegate.
iOS settings
iOS settings
iOS settings
Demo
Region monitoring
• Two types of regions in iOS: CLCircularRegion,
CLBeaconRegion
• An app can register up to 20 regions at a time. In
order to report region changes in a timely manner,
the region monitoring service requires network
connectivity.
if CLLocationManager.isMonitoringAvailableForClass(CLCircularRegion) {
let center = CLLocationCoordinate2D(latitude: 27.968056, longitude: -82.476389)
let radius = 50.0 * 1.60934 * 1000;
let identifier = "Tampa and vicinity"
let region = CLCircularRegion(center: center, radius: radius, identifier: identifier)
region.notifyOnEntry = true
region.notifyOnExit = true
locationManager?.startMonitoringForRegion(region)
}
Region monitoring
CLLocationManager CLLocationManagerDelegate
Getting the heading
and course of a device
• Core Location supports two different ways to get
direction-related information:
✴ Devices with a magnetometer can report the
direction in which a device is pointing, also
known as its heading.
✴ Devices with GPS hardware can report the
direction in which a device is moving, also
known as its course.
Getting the heading
and course of a device
CLLocationManager CLLocationManagerDelegate
Geocoding location data
• Location data is usually returned as a pair of numerical values
that represent the latitude and longitude of the corresponding
point on the globe.
• These coordinates offer a precise and easy way to specify
location data in your code but they aren’t very intuitive for users.
• Instead of global coordinates, users are more likely to understand
a location that is specified using information they are more
familiar with such as street, city, state, and country information.
• For situations where you want to display a user friendly version of
a location, you can use a geocoder object to get that information.
Geocoding location data
• A geocoder object uses a network service to convert
between latitude and longitude values and a user-
friendly placemark, which is a collection of data such
as the street, city, state, and country information.
• Forward geocoding is the process of converting
place name information into latitude and longitude
values.
• Reverse geocoding is the process of converting a
latitude and longitude into a placemark
Geocoding location data
• Forward geocoding
var geocoder: CLGeocoder?
let adressString = "500 East Kennedy Boulevard, Tampa, FL"
geocoder = CLGeocoder()
geocoder?.geocodeAddressString(adressString, completionHandler: { (placemarks, error) in
if let placemarks = placemarks {
for placemark in placemarks {
guard
let latitude = placemark.location?.coordinate.latitude,
let longitude = placemark.location?.coordinate.longitude else { continue }
print("Found placemark at: (latitude) (longitude)")
}
}
})
Found placemark at: 27.948594 -82.45609
let adressString = "Kennedy Boulevard, Tampa, FL”
…
Found placemark at: 27.9495842266901 -82.452392334991
Found placemark at: 27.9448699419791 -82.5009904807818
[CLPlacemark]?
Geocoding location data
• Reverse geocoding
var geocoder: CLGeocoder?
geocoder = CLGeocoder()
let location = CLLocation(latitude: 27.948594, longitude: -82.45609)
geocoder?.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in
if let placemarks = placemarks {
for placemark in placemarks {
if let addressDict = placemark.addressDictionary {
let address = ABCreateStringWithAddressDictionary(addressDict, false)
print("Formatted address:n(address)")
}
}
}
})
Formatted address:
500 E Kennedy Blvd
Tampa FL 33602
United States
Things I left out
• iBeacons (monitoring and turning an iOS device
into a beacon)
• Indoor positioning
• CLVisit
• Mapkit (maps, annotations, overlays, directions)
Reference
• Apple documentation
✴ Location and maps programming guide
✴ Core Location Framework Reference
Thanks!
Core Location in iOS
Juan Catalan
jcatalan007@gmail.com
https://www.slideshare.net/jcatalan007/core-location-in-ios
Bonus section
How the GPS works?
• The GPS system consists of three pieces. There
are the satellites that transmit the position
information, there are the ground stations that are
used to control the satellites and update the
information, and finally there is the receiver that is
built-in in the smartphone.
How the GPS works?
• It is the receiver that collects data from the
satellites and computes its location anywhere in
the world based on information it gets from the
satellites.
• There is a popular misconception that a GPS
receiver somehow sends information to the
satellites but this is not true, it only receives data.
How the GPS works?
How the GPS works?
• The goal of the system is to always provide at least 4
satellites somewhere in the visible sky. In practice there
are usually many more than this, sometimes as many as
12.
• In order to have good fix we need:
✴ Current almanac with ephemeris data for the satellites,
expected location, expected time
✴ Given this data the only thing it needs in order to
calculate a fix is the precise location of 3 (for a 2D fix) or
4 satellites (for a 3D fix).
How the GPS works?
• Time to initial fix: about 45 seconds, because of
the almanac with satellite ephemeris data
• However, it could take up to 5 minutes if all the
initial data is missing
• An A-GPS reduces the time to fix to a few
seconds, because it uses a data link to download
the initial data the GPS receiver needs for the fix
How the GPS works?

More Related Content

What's hot

Кут між прямими
Кут між прямимиКут між прямими
Кут між прямимиGdanuk
 
Многокутник та його елементи (Геометрія, 8 клас)
Многокутник та його елементи (Геометрія, 8 клас)Многокутник та його елементи (Геометрія, 8 клас)
Многокутник та його елементи (Геометрія, 8 клас)Formula.co.ua
 
Розв"язування систем рівнянь другого степеня з двома змінними
Розв"язування систем рівнянь другого степеня з двома зміннимиРозв"язування систем рівнянь другого степеня з двома змінними
Розв"язування систем рівнянь другого степеня з двома зміннимиsveta7940
 

What's hot (6)

функція у=коріньх
функція у=коріньхфункція у=коріньх
функція у=коріньх
 
Кут між прямими
Кут між прямимиКут між прямими
Кут між прямими
 
Өзара кері сандар
Өзара кері сандарӨзара кері сандар
Өзара кері сандар
 
функції
функціїфункції
функції
 
Многокутник та його елементи (Геометрія, 8 клас)
Многокутник та його елементи (Геометрія, 8 клас)Многокутник та його елементи (Геометрія, 8 клас)
Многокутник та його елементи (Геометрія, 8 клас)
 
Розв"язування систем рівнянь другого степеня з двома змінними
Розв"язування систем рівнянь другого степеня з двома зміннимиРозв"язування систем рівнянь другого степеня з двома змінними
Розв"язування систем рівнянь другого степеня з двома змінними
 

Similar to Core Location in iOS

Developing Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location ServicesDeveloping Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location ServicesNick Landry
 
MBLTDev: Phillip Connaughton, RunKepper
MBLTDev: Phillip Connaughton, RunKepper MBLTDev: Phillip Connaughton, RunKepper
MBLTDev: Phillip Connaughton, RunKepper e-Legion
 
Windows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsWindows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsOliver Scheer
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxvishal choudhary
 
Smart Way to Track the Location in Android Operating System
Smart Way to Track the Location in Android Operating SystemSmart Way to Track the Location in Android Operating System
Smart Way to Track the Location in Android Operating SystemIOSR Journals
 
I os developers_meetup_4_sessionon_locationservices
I os developers_meetup_4_sessionon_locationservicesI os developers_meetup_4_sessionon_locationservices
I os developers_meetup_4_sessionon_locationservicesMahboob Nur
 
12.Maps and Location
12.Maps and Location12.Maps and Location
12.Maps and LocationNguyen Tuan
 
Mobile applications chapter 6
Mobile applications chapter 6Mobile applications chapter 6
Mobile applications chapter 6Akib B. Momin
 
Boldly Go Where No Man Has Gone Before. Explore Geo on iPhone & Android
Boldly Go Where No Man Has Gone Before. Explore Geo on iPhone & AndroidBoldly Go Where No Man Has Gone Before. Explore Geo on iPhone & Android
Boldly Go Where No Man Has Gone Before. Explore Geo on iPhone & AndroidBess Ho
 
InMobi inDecode - All About Location on Mobile : Ian Anderson
InMobi inDecode -  All About Location on Mobile : Ian AndersonInMobi inDecode -  All About Location on Mobile : Ian Anderson
InMobi inDecode - All About Location on Mobile : Ian AndersonInMobi
 
Geographical information system
Geographical information systemGeographical information system
Geographical information systemgujjugamingarmor
 
An event driven campus navigation system on andriod121
An event driven campus navigation system on andriod121An event driven campus navigation system on andriod121
An event driven campus navigation system on andriod121Ashish Kumar Thakur
 
Geographical information systems
Geographical information systemsGeographical information systems
Geographical information systemsGift Musanza
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native appsInnovationM
 
Location-aware Query Processing
Location-aware Query ProcessingLocation-aware Query Processing
Location-aware Query Processingcnsaturn
 

Similar to Core Location in iOS (20)

Developing Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location ServicesDeveloping Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location Services
 
MBLTDev: Phillip Connaughton, RunKepper
MBLTDev: Phillip Connaughton, RunKepper MBLTDev: Phillip Connaughton, RunKepper
MBLTDev: Phillip Connaughton, RunKepper
 
Windows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and MapsWindows Phone 8 - 15 Location and Maps
Windows Phone 8 - 15 Location and Maps
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
 
Remote Sensing ppt
Remote Sensing pptRemote Sensing ppt
Remote Sensing ppt
 
Find me
Find meFind me
Find me
 
Smart Way to Track the Location in Android Operating System
Smart Way to Track the Location in Android Operating SystemSmart Way to Track the Location in Android Operating System
Smart Way to Track the Location in Android Operating System
 
I os developers_meetup_4_sessionon_locationservices
I os developers_meetup_4_sessionon_locationservicesI os developers_meetup_4_sessionon_locationservices
I os developers_meetup_4_sessionon_locationservices
 
12.Maps and Location
12.Maps and Location12.Maps and Location
12.Maps and Location
 
Mobile applications chapter 6
Mobile applications chapter 6Mobile applications chapter 6
Mobile applications chapter 6
 
Boldly Go Where No Man Has Gone Before. Explore Geo on iPhone & Android
Boldly Go Where No Man Has Gone Before. Explore Geo on iPhone & AndroidBoldly Go Where No Man Has Gone Before. Explore Geo on iPhone & Android
Boldly Go Where No Man Has Gone Before. Explore Geo on iPhone & Android
 
Where 2.0
Where 2.0Where 2.0
Where 2.0
 
InMobi inDecode - All About Location on Mobile : Ian Anderson
InMobi inDecode -  All About Location on Mobile : Ian AndersonInMobi inDecode -  All About Location on Mobile : Ian Anderson
InMobi inDecode - All About Location on Mobile : Ian Anderson
 
Geographical information system
Geographical information systemGeographical information system
Geographical information system
 
Geolocation and Mapping
Geolocation and MappingGeolocation and Mapping
Geolocation and Mapping
 
An event driven campus navigation system on andriod121
An event driven campus navigation system on andriod121An event driven campus navigation system on andriod121
An event driven campus navigation system on andriod121
 
Geographical information systems
Geographical information systemsGeographical information systems
Geographical information systems
 
Sensor's inside
Sensor's insideSensor's inside
Sensor's inside
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
 
Location-aware Query Processing
Location-aware Query ProcessingLocation-aware Query Processing
Location-aware Query Processing
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 

Core Location in iOS

  • 1. Core Location in iOS Juan Catalan jcatalan007@gmail.com
  • 2. Apps using location based information • Using location-based information in your app is a great way to keep the user connected to the surrounding world. Whether you use this information for practical purposes (such as navigation) or for entertainment, location- based information can enhance the overall user experience.
  • 3. Location based information • Location based information consists of two pieces: location services and maps • Location services are provided by the Core Location framework, which defines interfaces for obtaining information about the user’s location and heading (the direction in which a device is pointing). • Maps are provided by the Map Kit framework, which supports both the display and annotation of maps similar to those found in the Maps app.
  • 4. How the iPhone determines your location • The iPhone uses a Hybrid Positioning System to determine your location. • This system uses a combination of GPS, a crowd- sourced location database of nearby Wi-Fi hotspots and the cellular triangulation technique that determines your rough location based on cell tower signal strength.
  • 6. How to get the user’s location • Standard Location Service ✴ highly configurable way to get the current location and track changes • Significant-change Location Service ✴ get the current location and be notified when significant changes occur (> 500 m) • Region monitoring (aka geofences) ✴ boundary crossings for defined geographical regions and Bluetooth low-energy beacon regions
  • 7. How to get the user’s location • CLLocationManager • CLLocationManagerDelegate var locationManager: CLLocationManager? locationManager = CLLocationManager() locationManager?.delegate = self locationManager?.startUpdatingLocation() locationManager?.startMonitoringSignificantLocationChanges() func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) func locationManager(manager: CLLocationManager, didFailWithError error: NSError) func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
  • 8. Location services permissions • When In Use Authorization ✴ Used when the app is in the foreground or suspended • Always Authorization ✴ Used always ✴ Launches the app for region monitoring or significant location changes
  • 9. Location services permissions • When In Use Authorization var locationManager: CLLocationManager? locationManager = CLLocationManager() locationManager?.delegate = self locationManager?.requestWhenInUseAuthorization()
  • 10. Location services permissions • Always Authorization var locationManager: CLLocationManager? locationManager = CLLocationManager() locationManager?.delegate = self locationManager?.requestAlwaysAuthorization()
  • 11. Getting location information in the background • Enable capability • Enable property in CLLocationManager (iOS 9+) locationManager?.allowsBackgroundLocationUpdates = true
  • 12. Getting location information in the background • When do we need to enable background location updates in the app capabilities?
  • 13. Getting location information in the background • Check if the user has not disabled background app refresh globally or for the app switch UIApplication.sharedApplication().backgroundRefreshStatus { case .Available: print("Background updates are available for the app.") case .Denied: print("The user explicitly disabled background behavior for this app or for the whole system.”) case .Restricted: print("Background updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user.") }
  • 14. App launched by location events • When an app is relaunched because of a location update, the launch options dictionary passed to your application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method contains the UIApplicationLaunchOptionsLocationKey key. • The presence of that key signals that new location data is waiting to be delivered to your app. • To obtain that data, you must create a new CLLocationManager object and restart the location services that you had running prior to your app’s termination. When you restart those services, the location manager delivers all pending location updates to its delegate.
  • 18. Demo
  • 19. Region monitoring • Two types of regions in iOS: CLCircularRegion, CLBeaconRegion • An app can register up to 20 regions at a time. In order to report region changes in a timely manner, the region monitoring service requires network connectivity. if CLLocationManager.isMonitoringAvailableForClass(CLCircularRegion) { let center = CLLocationCoordinate2D(latitude: 27.968056, longitude: -82.476389) let radius = 50.0 * 1.60934 * 1000; let identifier = "Tampa and vicinity" let region = CLCircularRegion(center: center, radius: radius, identifier: identifier) region.notifyOnEntry = true region.notifyOnExit = true locationManager?.startMonitoringForRegion(region) }
  • 21. Getting the heading and course of a device • Core Location supports two different ways to get direction-related information: ✴ Devices with a magnetometer can report the direction in which a device is pointing, also known as its heading. ✴ Devices with GPS hardware can report the direction in which a device is moving, also known as its course.
  • 22. Getting the heading and course of a device CLLocationManager CLLocationManagerDelegate
  • 23. Geocoding location data • Location data is usually returned as a pair of numerical values that represent the latitude and longitude of the corresponding point on the globe. • These coordinates offer a precise and easy way to specify location data in your code but they aren’t very intuitive for users. • Instead of global coordinates, users are more likely to understand a location that is specified using information they are more familiar with such as street, city, state, and country information. • For situations where you want to display a user friendly version of a location, you can use a geocoder object to get that information.
  • 24. Geocoding location data • A geocoder object uses a network service to convert between latitude and longitude values and a user- friendly placemark, which is a collection of data such as the street, city, state, and country information. • Forward geocoding is the process of converting place name information into latitude and longitude values. • Reverse geocoding is the process of converting a latitude and longitude into a placemark
  • 25. Geocoding location data • Forward geocoding var geocoder: CLGeocoder? let adressString = "500 East Kennedy Boulevard, Tampa, FL" geocoder = CLGeocoder() geocoder?.geocodeAddressString(adressString, completionHandler: { (placemarks, error) in if let placemarks = placemarks { for placemark in placemarks { guard let latitude = placemark.location?.coordinate.latitude, let longitude = placemark.location?.coordinate.longitude else { continue } print("Found placemark at: (latitude) (longitude)") } } }) Found placemark at: 27.948594 -82.45609 let adressString = "Kennedy Boulevard, Tampa, FL” … Found placemark at: 27.9495842266901 -82.452392334991 Found placemark at: 27.9448699419791 -82.5009904807818 [CLPlacemark]?
  • 26. Geocoding location data • Reverse geocoding var geocoder: CLGeocoder? geocoder = CLGeocoder() let location = CLLocation(latitude: 27.948594, longitude: -82.45609) geocoder?.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) in if let placemarks = placemarks { for placemark in placemarks { if let addressDict = placemark.addressDictionary { let address = ABCreateStringWithAddressDictionary(addressDict, false) print("Formatted address:n(address)") } } } }) Formatted address: 500 E Kennedy Blvd Tampa FL 33602 United States
  • 27. Things I left out • iBeacons (monitoring and turning an iOS device into a beacon) • Indoor positioning • CLVisit • Mapkit (maps, annotations, overlays, directions)
  • 28. Reference • Apple documentation ✴ Location and maps programming guide ✴ Core Location Framework Reference
  • 29. Thanks! Core Location in iOS Juan Catalan jcatalan007@gmail.com https://www.slideshare.net/jcatalan007/core-location-in-ios
  • 31. How the GPS works? • The GPS system consists of three pieces. There are the satellites that transmit the position information, there are the ground stations that are used to control the satellites and update the information, and finally there is the receiver that is built-in in the smartphone.
  • 32. How the GPS works? • It is the receiver that collects data from the satellites and computes its location anywhere in the world based on information it gets from the satellites. • There is a popular misconception that a GPS receiver somehow sends information to the satellites but this is not true, it only receives data.
  • 33. How the GPS works?
  • 34. How the GPS works? • The goal of the system is to always provide at least 4 satellites somewhere in the visible sky. In practice there are usually many more than this, sometimes as many as 12. • In order to have good fix we need: ✴ Current almanac with ephemeris data for the satellites, expected location, expected time ✴ Given this data the only thing it needs in order to calculate a fix is the precise location of 3 (for a 2D fix) or 4 satellites (for a 3D fix).
  • 35. How the GPS works? • Time to initial fix: about 45 seconds, because of the almanac with satellite ephemeris data • However, it could take up to 5 minutes if all the initial data is missing • An A-GPS reduces the time to fix to a few seconds, because it uses a data link to download the initial data the GPS receiver needs for the fix
  • 36. How the GPS works?