Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

iPhone Location Aware Apps by Example Beginner''''s Guide pdf
PREMIUM
Số trang
387
Kích thước
14.8 MB
Định dạng
PDF
Lượt xem
1593

iPhone Location Aware Apps by Example Beginner''''s Guide pdf

Nội dung xem thử

Mô tả chi tiết

www.it-ebooks.info

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

www.it-ebooks.info

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])

www.it-ebooks.info

Credits

Author

Zeeshan Chawdhary

Reviewers

Sebastian Borggrewe

Taylor Jasko

Robb Lewis

Jose Luis Manners

Shuxuan Nie

Martin Selva

Alex Zaltsman

Acquisition Editor

Alina Lewis

Lead Technical Editor

Susmita Panda

Technical Editors

Lubna Shaikh

LLewellyn Rosario

Project Coordinator

Leena Purkait

Proofreader

Mario Cecere

Copy Editor

Leonard D'silva

Indexer

Monica Ajmera

Graphics

Manu Joseph

Production Coordinator

Shantanu Zagade

Cover Work

Shantanu Zagade

www.it-ebooks.info

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!

www.it-ebooks.info

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].

www.it-ebooks.info

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.

www.it-ebooks.info

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.it-ebooks.info

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.

www.it-ebooks.info

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

www.it-ebooks.info

Table of Contents

[ ii ]

Chapter 2: The Xcoder's World 29

Introducing Xcode 4 29

Xcode 4: Prerequisites and features 30

Prerequisites 30

Features 30

iOS 5 and Xcode 4.2: new and notable features 31

iOS 5 new features 32

Xcode 4.2's new features 33

Transitioning from Xcode3: What you need to know 34

Time for action – installation 36

Time for action – Hello Location 38

Tools for the overnight coders: HTML5 46

PhoneGap 48

Time for action – Using PhoneGap to build a Hello Location App 49

Time for action – using Titanium Appcelerator for building the Hello Location app 54

Time for action – Hello Location with Sencha Touch 59

Exploring location-based SDKs/APIs 63

Foursquare 63

Gowalla 64

Eventful and Last.fm API – some music is always good 65

Still more tools: SimpleGeo and Factual 66

Other Notable APIs – YQL and Location Labs 66

Summary 67

Chapter 3: Using Location in your iOS Apps—Core Location 69

Core Location framework – an overview 70

Time for action – location debugging 70

Core Location Services 72

Standard location 72

Significant change 73

Region monitoring 73

Geocoding and reverse Geocoding – CLGeocoder 74

Direction using heading 75

Core Location Manager – CLLocationManager 76

Time for action – checking for location service availability 77

User authorization 80

Time for action – using Core Location with user authorization 81

The CLLocation object 84

Time for action – receiving location updates in your application 85

Time for action – boundary monitoring with Location Manager 87

Extending Hello Location for nearby events 90

Important things to know before we begin 91

www.it-ebooks.info

Table of Contents

[ iii ]

Time for action – extending Hello Location for nearby events 91

Time for action – Last.fm API in your app 97

What just happened? 98

Extending Hello Location for local search 99

Important things to know before we begin 100

Time for action – building a local search app with foursquare 100

Summary 103

Chapter 4: Using Maps in your iOS apps—MapKit 105

Overview of the MapKit framework 105

Understanding map geometry 106

Time for action – using MapKit in your app 108

Time for action – using map gestures – panning and zooming 115

Annotating Maps – an overview 117

Time for action – adding annotations to your maps 117

Time for action – draggable annotations 119

Time for action – custom map annotations 123

Map overlays – an overview 126

Time for action – customizing map annotations 126

User tracking modes 129

Bonus – offline maps in your app 130

Time for action – using OpenStreetMaps with CloudMade API 131

Summary 134

Chapter 5: Weather App—WeatherPackt 135

Storing and retrieving the user's location with SQLite 136

Time for action – storing and retrieving the user's location with SQLite 136

Converting location data into city name – using Geonames API 142

A bit on GeoNames 142

Time for action – converting location data into city name 143

Consuming the WeatherBug API 148

Important things to know before we begin 148

Time for action – using WeatherBug API 150

Building your Weather App: WeatherPackt 162

Start a new Xcode project 162

Define the Home screen 165

Time for action – defining the Home screen 165

Set up a default location 168

Formatting the Weather API for display 169

The settings page 169

Bonus: building WeatherPackt with PhoneGap 174

Bonus: text-to-speech 174

Summary 177

www.it-ebooks.info

Table of Contents

[ iv ]

Chapter 6: Events App—PacktEvents 179

PacktEvents: Overview and architecture 180

Architecture of PacktEvents 180

Storing and Retrieving Events with SQLite 181

Time for action – storing and retrieving events with SQLite 182

Plotting events on a map 191

Time for action – plotting events on a map 192

Filtering Events display by Event Categories 197

Time for action – filtering Events by categories 198

Using the Event Kit framework to add events to your iPhone calendar 205

Time for action – adding events to your iPhone calendar 207

Using the Twitter framework 210

Time for action – adding Twitter capabilities to your iPhone app 210

Bonus: using the Layar Player API in your app: Augmented Reality 213

Time for action – adding Augmented Reality to your iPhone app 213

PacktEvents: building the app 219

Summary 220

Chapter 7: Advanced Topics 221

Using directions with location 222

Direction using heading 222

Getting your app ready for direction 222

Understanding heading using magnetometer 222

Time for action – using heading for direction in your app 223

Direction using course 226

Time for action – using course for direction in your app 226

Core Motion: Motion Manager 229

How to use Core Motion 230

Time for action – using MotionManager: accelerometer 231

Core Motion conclusion 235

Background app execution 235

What apps can run in the background? 236

Background location 236

Push notifications - overview 240

Local notifications 241

Time for action – using local notifications 241

Summary 246

Chapter 8: Local Search—PacktLocal 247

Consuming the foursquare venue API 248

Venue categories 248

Time for action – consuming the foursquare venue API - categories 248

Recommended and popular venues 255

www.it-ebooks.info

Table of Contents

[ v ]

Time for action – recommended and popular venues 255

Search for venues 262

Time for action – exploring the foursquare Search API 263

Building an UI for our local search app - PacktLocal 267

Saving venue information on the device 268

Building the app: PacktLocal 268

Time for action – building the app - PacktLocal 269

Summary 282

Chapter 9: Location Aware News—PacktNews 283

Understanding the Patch News API – HyperLocal News 283

Authentication 284

Taxonomy 284

Vertical 285

Format 285

Author 285

Finding stories by location 285

Find location by names 286

Time for action – consuming the Patch News API 286

Adding the Geo Fencing support 295

Time for action – adding the Geo Fencing support 296

Building our app - PacktNews 299

A bit on StoryBoard 299

Time for action – building PacktNews 300

Summary 313

Chapter 10: Social Governance—TweetGovern 315

Social governance – an overview 316

TweetGovern – behind the scenes 316

Stackmob 318

Our approach: Twitter 319

Icons and images 322

SDKs and frameworks 322

Time for action – creating the UI for TweetGovern 323

Time for action – detecting the user location and showing nearby issues 326

Time for action – creating and voting for an issue 335

Summary 347

Appendix: Pop-Quiz Answers 349

Index 353

www.it-ebooks.info

www.it-ebooks.info

Tải ngay đi em, còn do dự, trời tối mất!