iPhone Location Aware Apps by Example Beginner's Guide Build five complete location-enabled apps from scratch—from idea to implementation! Zeeshan Chawdhary BIRMINGHAM - MUMBAI iPhone Location Aware Apps by Example Beginner's Guide Copyright © 2012 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: March 2012 Production Reference: 1160312 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-224-3 www.packtpub.com Cover Image by Asher Wishkerman ([email protected]) Credits Author Project Coordinator Zeeshan Chawdhary Leena Purkait Reviewers Proofreader Sebastian Borggrewe Mario Cecere Taylor Jasko Robb Lewis Copy Editor Leonard D'silva Jose Luis Manners Shuxuan Nie Indexer Martin Selva Monica Ajmera Alex Zaltsman Graphics Acquisition Editor Manu Joseph Alina Lewis Production Coordinator Lead Technical Editor Shantanu Zagade Susmita Panda Cover Work Technical Editors Shantanu Zagade Lubna Shaikh LLewellyn Rosario About the Author Zeeshan Chawdhary has been a keen developer for the last six years, and has worked in the location-based space for the past five years. He is currently the Chief Technology Officer of Wcities Inc, a San Francisco-based Location Content Provider. He is currently experimenting with PostGIS, PhoneGap, and iOS 5, and is currently trying his hand at blogging again at http://justgeeks.in. I would like to thank all the lovely people at PacktPub, especially Mary Nadar for having introduced me to the PacktPub family. A special thanks to Leena, Susmita, Lubna, and Llewellyn for working with me tirelessly on the book. I would also thank Christopher D. Sloop from WeatherBug, Lauren Sperber and Janine Iamunno from AOL Patch.com, Tim Breidigan, and Robert Martindale from Eventful.com – for having allowed me to use their respective APIs in the book, you guys rock man! About the Reviewers Sebastian Borggrewe, born and raised in Germany, is a computer science Master's student at the University of Edinburgh/RWTH Aachen. Since he was 16, he has been freelancing for several web and mobile agencies, and has founded his own agency. Currently, he is the co-founder and CTO of Loyalli Ltd., a London-based startup, developing mobile loyalty card solutions (http://www.loyalli.com). When he is not coding, he is searching for new technology or ways to use technology to make life even more fun. You will probably find him hanging out with friends, hitting the gym, cooking, or playing the guitar in his 60's band. One of his goals in life, apart from working in a kick-ass office in central London with an "office slide", is obtaining a pilot license. More information about Sebastian, and his projects can be found at http://www.sebastianborggrewe.de. Taylor Jasko has been fascinated with technology ever since the day he laid his hands on a Windows 95-based computer. Since then, now being eighteen years old, he has dived into web design and development, computer programming, and even system administration with his favorite server-oriented operating system, Debian Linux. He founded the technology blog Tech Cores (http://techcores.com), and has been working on it ever since it was created back in late 2008. Tech Cores is a great example of his work; he designed and created it using the powerful WordPress content management system, and with the help of his Wacom Intuos4 graphic tablet plus Adobe Photoshop. While in school, he can be found freelancing graphic design and programming work. His technical strengths include PHP, JavaScript (including libraries such as jQuery), AJAX, HTML, CSS, Perl, Objective-C, Linux/UNIX, MySQL, Apache, Nginx, and to finish it all off, a dab of Python. Essentially, he is a programmer, system admin, and a designer! He can be reached at [email protected]. Jose Luis Manners is a seasoned IT professional with over 20 years of software development experience, including project management, technical architecture, and full life-cycle systems development. His software development experience includes enterprise systems for Fortune 500 clients as well as federal, state, and local governments. Mr. Manners has been recognized on several occasions by Microsoft with their Most Valuable Professional award for his outstanding work with .NET, and his contributions to Microsoft's product teams. He specializes in .NET, iOS, and Android mobile development for clients in the Washington, DC metropolitan area. He can be reached at [email protected]. Shuxuan Nie is a SOA Consultant, specializing in SOA and Java technologies. She has more than 10 years of experience in the IT industry that includes SOA technologies, such as BPEL, ESB, SOAP, XML, and Enterprise Java technologies, Eclipse plugins, and other areas, such as C++ cross-platform development. Since 2010, Shuxuan has been working in Rubiconred, and has been helping customers resolve integration issues. From 2007 to 2010, Shuxuan had been working in Oracle Global Customer Support team, and focussed on helping customers solve their middleware/SOA integration problems. Before joining Orcale, Shuxuan had been working in IBM China Software Development Lab for four years as staff software engineer, where she participated in several complex products on IBM Lotus Workplace, Webshpere and Eclipse platform, and then joined the Australia Bureau of Meteorology Research Center, which is responsible for implementation of Automated Thunderstorm Interactive Forecast System for Aviation and Defence. Shuxuan holds an MS in the Computer Science degree from Beijing University of Aeronautics and Astronautics. Martin Selva heads the Gaming team at Hungama Digital Media Entertainment Pvt Ltd, with over nine years of experience. His passion, experience, and expertise have also helped him develop a keen interest in Product Development for Online & Devices. At Hungama, Martin is responsible for building a gaming portal called www.thegamebox. com, and heads a Gaming Studio that comprises of iOS Developers, PHP Developers, Game Designers, and Content Writers. He can be reached at [email protected] and [email protected]. Alex Zaltsman is the CEO and founder of Xcela Mobile, a software and mobile cloud infrastructure hosting company that develops applications for mobile devices, such as the iPhone, iPad, and Android. Prior to finding TourSpot, Alex was a co-founder and managing partner of a technology services company. Alex has been in the technology field for over 15 years. Prior to founding the technology services company, Mr. Zaltsman worked at Lucent Technologies, AT&T Labs, and Johnson & Johnson, in technical and management capacities. Alex is also on the Board of Advisors of BizWorld, a non-profit organization that has created curriculum for teaching entrepreneurship and money management to kids. Alex is on the Board of Directors for the New Jersey chapter for Entrepreneurs Organization (http://www.eonetwork.org). www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@ packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: The Location-based World 7 Understanding Location-based Services 8 Time for action – consuming Location-based Services with Google 9 Buzzwords in the Location-based Industry 11 Application of LBS and common use cases 13 Military 13 Government 13 Commercial 13 How Apple uses LBS in the iPhone, iPad, and iPod devices 14 iOS location API 15 Time for action – turning off Location Tracking in your iPhone 15 Behind LBS – GPS 17 User segment 17 Space segment 18 Control segment 18 Push and Pull methods of Location Services 18 Push Service 18 Pull Service 19 Life without GPS: Wi-Fi-based location detection 19 Life without GPS: cell ID positioning and cell tower triangulation 21 Time for action – using the SkyHook Wireless Loki framework to determine your location 22 Life without GPS: Google Maps API 23 Understanding Indoor and Outdoor Navigation 26 Summary 27