IPhone and Location(1)Documents User Location
1. Introduce Location and Map
Getting the User's Location
Region Monitoring
Geocoding Location Data
iBeacons Enhance the User's Experience of a Location
Heading Information Indicates the User's Current Orientation - magnetometer
1.1 Getting the User's Location
Core Location Framework
a. The significant-change location service provides a low-power way to get the current location and be notified.
b. The standard location service
c. Region monitoring, monitor boundary crossings for defined geographical regions and Bluetooth low energy beacon regions.
Linking to a Library or Framework
Select the Project-----> Select Targets -----> Build Phases-----> Link Binary With Libraries----> Click on +
#import <CoreLocation/CoreLocation.h>
Requiring the Presence of Location Services in Order to Run
Info.plist
UIRequiredDeviceCapabilities= array of strings
a. location-services string if you require location services in general.
b. gps string if your app requires the accuracy offered only by GPS hardware.
Getting the User's Current Location
The core location framework uses information obtained from the built-in cellular, Wi-Fi or GPS hardware to triangulate a location.
standard location service
significant-change location service
Gathering location data is power-intensive operation.
Power up the onboard radios and querying the available cell towers, Wi-Fi hotspots, or GPS satellites. Leaving the standard location service running for extended periods can drain the device's battery.
The significant-change location service reduces battery drain by monitoring only cell tower changes.
Determining Whether Location Services Are Available
a. The user can disable location Services in the App Settings
b. The user can deny location services for a specific app.
c. The device might be in Airplane mode and unable to power up the necessary hardware.
We call CLLocationManager.locationServicesEnabled to check that.
Starting the Standard Location Service
Create an instance of CLLocationManager, configure desiredAccuracy and distanceFilter.
Assign a delegate to the object and call the startUpdatingLocation.
To stop the delivery of location updates, call stopUpdatingLocation.
-(void)startStandardUpdates{
if(nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 500; //meters
[locationManager startUpdatingLocation];
}
Starting the Significant-Change Location Service
create an instance of the CLLocationManager, assign a delegate to it, call the startMonitoringSignificantLocationChanges
-(void) startSignificantChangeUpdates{
if(nil == locationManager){
locationManager = [[CLLocationManager alloc]init];
}
locationManager.delegate = self;
[locationManager startMonitoringSignificantLocationChanges];
}
stopMonitoringSignificantLocationChanges to stop the service.
If we leave this service running and our app is suspended or terminated, the service automatically wakes up our app when new location data arrives.
At wake-up time, our app is put into the background and given a small amount of time(10 seconds) to process the location data. Our app is in the background and should do minimal work and avoid any tasks(such as querying the networks).If the time expires, our app may be terminated.
If we need more time, we need to request more time using the beginBackgroundTaskWithExpirationHandler, end the task by calling the endBackgroundTask
Receiving Location Data from a Service
locationManager:didUpdateLocations
Sometimes, location manager returns cached events, so we need to check the timestamp of any location events we receive.
-(void) locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if(abs(howRecent) < 15.0){
NSLog(@"latitude %+.6f, longitude %+.6f\n", location.coordinate.latitude, location.coordinate.longitude);
}
}
Getting Location Events in the Background
Declare our app as needing background location services by including the UIBackgroundModes in Info.plist.
When an app is in the background and the location data is unlikely to change, in iOS 6.0 and later the location manager pauses the delivery of location updates to its delegate and powers down the hardware. After the user launches the app or when the user begins the activity again, the location manager resumes delivering location updates.
How to pause is decided by activityType, for example CLActivityTypeAutomotiveNavigation.
When the location manager pauses location updates, it calls the locationManagerDidPauseLocationUpdates
When the location manager resume location updates, it calls the locationManagerDidResumeLocationUpdates
If your paused, background app is terminated by the user or if it is terminated by the system to free up memory for the current foreground app, location updates will not resume automatically the next time the app is launched.
Deferring Location Updates While in the Background
deferredLocationUpdatesAvailable on CLLocationManager to see if the device support this.
-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
[self.hike addLocations:locations];
if(!self.defferingUpdates){
CLLocationDistance distance = self.hike.goal - self.hike.distance;
NSTimeInterval time = [self.nextAudible timeIntervalSinceNow];
[locationManager allowDeferredLocationUpdatesUntilTraveled:distance
timeout:time];
self.defferingUpdates = YES;
}
}
Tips for Conserving Battery Power
…snip...
References:
Location and Maps Guide
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009497-CH1-SW1
API book
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CoreLocation_Framework/_index.html#//apple_ref/doc/uid/TP40007123
sample
https://developer.apple.com/library/ios/search/?q=location+sample
tips
http://www.cocoachina.com/special/fornew.html
https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html#//apple_ref/doc/uid/TP40010155-CH17
Guide
https://developer.apple.com/library/ios/navigation/#section=Resource%20Types&topic=Getting%20Started
- 浏览: 2567119 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
发表评论
-
ionic UI(5)UI and Backend
2016-12-02 03:22 606ionic UI(5)UI and Backend 1 Pr ... -
Stanford Cource(2)Demo App Caculator
2014-06-24 01:29 917Stanford Cource(2)Demo App Ca ... -
Mono on MAC
2014-06-04 03:27 1002Mono on MACJust fine the tool f ... -
IOS7 App Development Essentials(4)IPhone5, IPhone5s, IPhone5c
2014-04-11 03:59 1000IOS7 App Development Essentia ... -
IOS7 App Development Essentials(3)NSUserDefaults
2014-04-11 02:58 1023IOS7 App Development Essentia ... -
IPhone and Location(2)Documents Region Monitoring and Region Sample
2013-10-18 05:10 1751IPhone and Location(2)Documents ... -
Learn Objective C(6)Programming with Objective-C - Working with Blocks and Deali
2013-10-18 00:02 945Learn Objective C(6)Programming ... -
Learn Objective C(5)Programming with Objective-C - Working with Protocols and Va
2013-10-17 23:47 1016Learn Objective C(5)Programming ... -
Learn Objective C(4)Programming with Objective-C - Encapsulating Data and Custom
2013-10-17 23:23 950Learn Objective C(4)Programming ... -
Learn Objective C(3)Programming with Objective-C - Defining Classes, Working wit
2013-10-17 23:09 1039Learn Objective C(3)Programmi ... -
Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6
2013-10-17 00:30 991Learn Objective C(2)Learn Obj ... -
Learn Object C(1) Learn Objective-C in Day 6 - 1 ~ 3
2013-10-17 00:22 1125Learn Object C(1) Learn Objec ... -
APNS(4)Recall the Process and Learn Java APNS
2013-04-18 02:48 3493APNS(4)Recall the Process and L ... -
Build the iOS Things with J2Objc
2013-04-12 03:25 2481Build the iOS Things with J2Obj ... -
APNS(3)Write the Easy Client App
2013-01-15 07:23 1749APNS(3)Write the Easy Client Ap ... -
APNS(2)Try to Finish the first Example
2013-01-14 07:56 1561APNS(2)Try to Finish the first ... -
Stanford Cource(1)MVC and Object-C
2012-12-14 14:04 1345Stanford Cource(1)MVC and Objec ... -
Some VI Tips
2012-11-15 04:48 1107Some VI Tips Today, I need to c ... -
MAC Mini Setup
2012-09-25 18:45 1353MAC Mini Setup I am dealing wit ... -
Android Talker(1)MAC Environment
2012-09-01 00:16 1942Android Talker(1)MAC Environmen ...
相关推荐
python学习资源
jfinal-undertow 用于开发、部署由 jfinal 开发的 web 项目
基于Andorid的音乐播放器项目设计(国外开源)实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
python学习资源
python学习资源
python学习一些项目和资源
【毕业设计】java-springboot+vue家具销售平台实现源码(完整前后端+mysql+说明文档+LunW).zip
HTML+CSS+JavaScarip开发的前端网页源代码
python学习资源
【毕业设计】java-springboot-vue健身房信息管理系统源码(完整前后端+mysql+说明文档+LunW).zip
成绩管理系统C/Go。大学生期末小作业,指针实现,C语言版本(ANSI C)和Go语言版本
1_基于大数据的智能菜品个性化推荐与点餐系统的设计与实现.docx
【毕业设计】java-springboot-vue交流互动平台实现源码(完整前后端+mysql+说明文档+LunW).zip
内容概要:本文主要探讨了在高并发情况下如何设计并优化火车票秒杀系统,确保系统的高性能与稳定性。通过对比分析三种库存管理模式(下单减库存、支付减库存、预扣库存),强调了预扣库存结合本地缓存及远程Redis统一库存的优势,同时介绍了如何利用Nginx的加权轮询策略、MQ消息队列异步处理等方式降低系统压力,保障交易完整性和数据一致性,防止超卖现象。 适用人群:具有一定互联网应用开发经验的研发人员和技术管理人员。 使用场景及目标:适用于电商、票务等行业需要处理大量瞬时并发请求的业务场景。其目标在于通过合理的架构规划,实现在高峰期保持平台的稳定运行,保证用户体验的同时最大化销售额。 其他说明:文中提及的技术细节如Epoll I/O多路复用模型以及分布式系统中的容错措施等内容,对于深入理解大规模并发系统的构建有着重要指导意义。
基于 OpenCV 和 PyTorch 的深度车牌识别
【毕业设计-java】springboot-vue教学资料管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
此数据集包含有关出租车行程的详细信息,包括乘客人数、行程距离、付款类型、车费金额和行程时长。它可用于各种数据分析和机器学习应用程序,例如票价预测和乘车模式分析。
把代码放到Word中,通过开发工具——Visual Basic——插入模块,粘贴在里在,把在硅基流动中申请的API放到VBA代码中。在Word中,选择一个问题,运行这个DeepSeekV3的宏就可以实现在线问答
【毕业设计】java-springboot+vue机动车号牌管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
【毕业设计】java-springboot-vue交通管理在线服务系统的开发源码(完整前后端+mysql+说明文档+LunW).zip