`
sillycat
  • 浏览: 2539741 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

IPhone and Location(1)Documents User Location

 
阅读更多

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

分享到:
评论

相关推荐

    Head First iPhone and iPad Development, 3rd Edition

    A Learner’s Guide to Creating Objective-C Applications for the iPhone and iPad Book Description : Let’s say you have a killer app idea for iPhone and iPad. Where do you begin? Head First iPhone and...

    location-cleaned 定位ios15.0 最新驱动-iOS专用

    1. 导航应用:location-cleaned驱动为地图和导航应用提供了更准确的位置信息,确保用户能够获得实时的路线指引。 2. 社交媒体:用户在分享位置信息时,location-cleaned驱动可以确保只分享他们愿意公开的范围,保护...

    Location-cleaned IOS14.8驱动包

    1. **设备识别**:驱动程序是操作系统与硬件设备之间的桥梁,它帮助操作系统识别并控制硬件设备,如iPhone或iPad。iOS 14.8驱动包确保计算机能够正确识别连接的iOS设备。 2. **数据传输**:驱动包支持数据的快速、...

    iOS 10 SDK Development: Creating iPhone and iPad Apps with Swift

    iOS 10 SDK Development: Creating iPhone and iPad Apps with Swift by Chris Adamson English | 24 Mar. 2017 | ASIN: B071RRCK9R | 264 Pages | AZW3 | 5.24 MB All in on Swift! iOS 10 and Xcode 8 make it ...

    Head First iPhone and iPad Development, 2nd Edition.pdf

    Head First iPhone and iPad Development, 2nd Edition.pdf

    location16.0 ios可用

    描述中的“ios可用”确认了这个更新或软件兼容于iOS设备,用户可以在iPhone或iPad上安装并使用。通常,当开发者发布新版本时,他们会确保新版本与当前主流的iOS版本兼容,以覆盖广泛的用户群体。 基于提供的标签...

    Iphone User Guide

    Describe how to use iphone, just for user

    Programming.the.iPhone.User.Experience

    and elaborates on the most important concepts in the iPhone user experience. Chapter 3, Types of Cocoa Touch Applications, presents a vocabulary for describing families of applications for the ...

    Developing iOS 7 Apps for iPhone and iPad ppt (1-10)

    斯坦福大学的"Developing iOS 7 Apps for iPhone and iPad"课程是学习如何构建iOS应用程序的宝贵资源,尤其适合初学者和有经验的开发者。这门课程采用最新的Xcode 5作为开发环境,针对苹果公司的操作系统iOS 7进行...

    Building iPhone and iPad Electronic Projects

    1. 构建iPhone和iPad电子项目的基本概念:这本书的标题《Building iPhone and iPad Electronic Projects》揭示了内容的主要方向,即教授如何在iPhone和iPad上构建电子项目。这可能涉及到硬件接口,软件编程,以及...

    Location-cleaned IOS15.1驱动包

    iOS系统作为苹果公司为其iPhone、iPad等产品设计的操作系统,其稳定性和兼容性是用户关注的焦点。在最新的iOS 15.1版本中,驱动程序扮演着至关重要的角色,它们直接影响着设备的性能和功能体验。本文将详细介绍...

    Location-cleaned14.4驱动

    在iOS系统中,驱动程序同样负责确保操作系统能够正确地与iPhone或iPad的硬件组件通信,例如处理器、触摸屏、摄像头、无线网络模块等。 "Location-cleaned"这个术语可能是指这款驱动进行了特定的优化或者清理工作,...

    iPhone.2G.and.3G.User.Guide.2008

    《iPhone 2G and 3G User Guide 2008》PDF文件提供了全面的教程,不仅适合新用户入门,也对已有用户有很好的参考价值,可以帮助他们更好地理解和利用手中的设备。通过深入学习这份指南,用户可以充分发挥iPhone 2G和...

    Learn iPhone and iPad Cocos2D Game Developmentn中文版

    《Learn iPhone and iPad Cocos2D Game Development》中文版是一本专为苹果移动平台开发者设计的游戏开发教程。Cocos2D是一款广泛使用的2D游戏引擎,尤其在iOS平台上备受青睐,因为它提供了强大的图形渲染能力、丰富...

    [iPhone开发书籍大全].Professional.iPhone.and.iPod.Touch.Programming(Wrox.2008).pdf

    How to design and implement an iPhone user interface Ways to enable and optimize web sites for iPhone and iPod touch. Tips for handling touch interactions and capturing JavaScript events Specific CSS ...

    Learn iPhone and iPad cocos2d Game Development中文版全集

    《Learn iPhone and iPad cocos2d Game Development中文版全集》是一部深入浅出的教程,旨在帮助读者掌握在iOS平台上使用cocos2d框架开发游戏的技能。cocos2d是一款强大的2D游戏开发库,特别适合于iPhone和iPad应用...

    Location-cleaned驱动更新至14.3

    可能包括对新硬件的支持,比如新的iPhone型号,或者对某些应用程序的性能增强。此外,14.3驱动也可能引入了新的节能技术,提高了设备的整体效率。 驱动程序作为操作系统与硬件之间的桥梁,其更新对于设备的正常运行...

    iPhone.SDK.3.Programming:Advanced.Mobile.Development.for.Apple.iPhone.and.iPod.touch(Wiley.2009-9).pdf

    Covers the complete application development process, and highlights all the key device features including the camera, location awareness, and more Completely revised and redesigned with more than 100...

    iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch

    《iPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch》是一本深入探讨苹果iPhone和iPod touch高级移动开发技术的专业书籍。本书由Maher Ali博士撰写,他是贝尔实验室(Bell ...

Global site tag (gtag.js) - Google Analytics