ebook img

Geolocation in iOS PDF

114 Pages·2012·15.11 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Geolocation in iOS

www.it-ebooks.info www.it-ebooks.info Geolocation in iOS Alasdair Allan Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo www.it-ebooks.info Geolocation in iOS by Alasdair Allan Copyright © 2012 Alasdair Allan. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or [email protected]. Editors: Shawn Wallace and Brian Jepson Cover Designer: Karen Montgomery Production Editor: Kara Ebrahim Interior Designer: David Futato Proofreader: Kara Ebrahim Illustrator: Rebecca Demarest October 2012: First Edition. Revision History for the First Edition: 2012-10-01 First release See http://oreilly.com/catalog/errata.csp?isbn=9781449308445 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Geolocation in iOS, the image of a brindled gnu, and related trade dress are trade- marks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. ISBN: 978-1-449-30844-5 [LSI] 1349100417 www.it-ebooks.info Table of Contents Preface ...................................................................... v 1. Introduction ........................................................... 1 Hardware Support 1 Detecting Hardware Differences 2 GPS Availability 2 Compass Availability 2 Setting Required Hardware Capabilities 3 Background Modes 3 2. Core Location ........................................................... 5 The Standard Location Service 5 Basic Usage 6 Reporting the User’s Position 7 Adding a User Interface 11 Significant Location Monitoring 16 Continuous Location Monitoring 18 Sending Your Location to a Database 20 Region Monitoring 31 Adding Region Monitoring 31 Adding Local Notifications 33 3. Map Kit .............................................................. 37 Adding a Map 37 Annotating Maps 45 Adding Overlays 48 4. Digital Compass ....................................................... 51 About the Magnetometer 51 Writing a Compass Application 53 Determining the Heading in Landscape Mode 56 iii www.it-ebooks.info 5. Geocoding ............................................................ 63 Reverse Geocoding 63 Using Alternative Reverse Geocoding Services 64 Forward Geocoding 64 Building an Example App 65 CLPlacemark Objects 74 Adding CLPlacemarks to Maps 74 6. Drawing Heat Maps .................................................... 81 Building an Earthquake Map 81 Adding Earthquake Data 82 Building the User Interface 84 Adding the Overlay 85 Adding the Heat Map 89 Overlaying Other Data 92 Overlaying Other Types of Images 94 7. Further Information and Third-Party SDKs ................................. 97 Skyhook Wireless 97 SpotRank 97 Local Faves 98 GeoLoqi 98 MapBox 98 Bing Maps Control for iOS 99 ArcGIS for iOS 100 Urban Airship 102 Foursquare 102 iv | Table of Contents www.it-ebooks.info Preface The mobile phone—specifically the iPhone, which continues to define the state of the art for smartphones—has become the primary interface device for geographically- tagged data. Who Should Read This Book? This book provides an introduction to the hot topic of location on the iOS platform. If you are a programmer who has had some experience with iOS before, this book will help you push your knowledge further. If you are an experienced Mac programmer and are already familiar with Objective-C as a language, this book will dive deeper into Core Location and Map Kit, as well as some of the more important third-party tools, to give you a close look at the geolocation capabilities of the iOS platform. What Should You Already Know? This book assumes some previous experience with the Objective-C language. Addi- tionally, some familiarity with the iOS platform would be helpful. If you’re new to the iOS platform you may be interested in Learning iOS Programming, also by Alasdair Allan (O’Reilly). What Will You Learn? This book will guide you through developing applications for the iOS platform. These applications make use of the onboard sensors and geolocation capabilities of the device in your hands to give you the background and skills to build your own applications using the hottest location-aware technology for any mobile platform. v www.it-ebooks.info What’s In This Book? Chapter 1 This chapter summarizes the available sensors on the iPhone and iPad platforms and how they could be used in applications. It talks about the differences between the hardware platforms. Chapter 2 This chapter includes a discussion on the Core Location framework, covering standard location monitoring as well as the significant-change location service, which provides a low-power way to get the current location and be notified of changes to that location. It also covers region monitoring, which provides geo- fencing capabilities on the platform. Chapter 3 This chapter includes a discussion on the MapKit framework, which allows you to embed maps directly into your application’s views, and provides support for an- notating these maps. Chapter 4 This chapter shows how to use the onboard magnetometer, which is present in many iOS devices, as a digital compass using the Core Location framework. Chapter 5 This chapter discusses the geocoding capabilities of the platform that allow you to go from a latitude and longitude to a place name, and vice versa. Chapter 6 This chapter walks through code that allows you to display heat maps on top of a standard Map Kit view. Chapter 7 This chapter points to more information and some of the available third-party software development kits (SDKs) that make it easier to carry out geocoding, geo- fencing, and real-time location streaming as part of your application. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. vi | Preface www.it-ebooks.info Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter- mined by context. This icon signifies a tip, suggestion, or general note. This icon signifies a warning or caution. Using Code Examples This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Geolocation in iOS, by Alasdair Allan. Copyright 2012 O’Reilly Media, Inc., ISBN 978-1-4493-0844-5.” If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at [email protected]. Safari® Books Online Safari Books Online (www.safaribooksonline.com) is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business. Technology professionals, software developers, web designers, and business and cre- ative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training. Safari Books Online offers a range of product mixes and pricing programs for organi- zations, government agencies, and individuals. Subscribers have access to thousands Preface | vii www.it-ebooks.info of books, training videos, and prepublication manuscripts in one fully searchable da- tabase from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Tech- nology, and dozens more. For more information about Safari Books Online, please visit us online. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://oreil.ly/geolocation-ios. Supplementary materials are also available at http://www.programmingiphonesensors.com/. To comment or ask technical questions about this book, send email to [email protected]. For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com. Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Acknowledgments Everyone has one book in them. This isn’t it; it’s my fifth, and hopefully not my last by any means. Nonetheless, they don’t really get much easier to write. I’d therefore like to thank my editors Brian Jepson and Shawn Wallace for prodding and poking until I actually finally set some of this material down in print. I’d also like to thank my long- suffering wife, Gemma Hobson. I’m not entirely sure why she lets me keep writing; it’s almost certainly nothing to do with the royalty checks. Finally, to my son Alex, who is still young enough that he’s not entirely sure what daddy is doing. Sorry for being so grumpy while I went about this whole business one more time. viii | Preface www.it-ebooks.info

Description:
Location and Map Kit, as well as some of the more important third-party ative professionals use Safari Books Online as their primary resource for Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Open a Terminal window, and at the command prompt type the code shown in
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.